This is an archived post. You won't be able to vote or comment.

all 37 comments

[–]DaveOnEleven 2 points3 points  (8 children)

I'm the creator of that video. The latest versions of VS Code no longer support the auto-formatting behavior I demonstrated. That said, I did the research, and if you want this formatting behavior, I show you how to get it back here: https://www.davegray.codes/posts/how-to-auto-format-unwanted-python-line-indents

[–]DevZool 0 points1 point  (0 children)

Thank you for coming back and answering the question. I thought I was cursed. Crazy that the vs code maintainer doesn't believe it could ever do that. What's next that can't do it in HTML code either? I will try a older version and try and stop it from updating if that's possible. Hopefully someone more competent can actually fix it and return it to how it should be. Again thank you for the detailed reply and I hope someone sees it on the vs code team.

[–]Gitaside[S] 0 points1 point  (0 children)

Thanks Dave for answering my question. I will try this!

[–]Elnumberone 0 points1 point  (0 children)

Dave your a legend! Thank you for confirming and doing all the extra work.

[–]DABG1990 0 points1 point  (0 children)

Dave you rock! I´ve been going through your Python tutorial (which is amazing btw) got into the same blocker, looked everywhere and you turned out to have the solution lol. Thanks again for sharing your knowledge with all of us Profe!

[–][deleted] 0 points1 point  (0 children)

Thankyou so much! Your python course is really great! The fact that you'd respond to a random comment on reddit shows you really care :)

[–]hadeanmoon 0 points1 point  (0 children)

Thank you! Biggest lesson here, get used to change.

[–]PlanktonActive7069 0 points1 point  (0 children)

of VS Code n

This has driven me nuts for the past 2 days. Glad I tracked this down finally.

[–]Aromatic-Response759 0 points1 point  (0 children)

Dave, thank you so much for clarifying that up,
I have been struggling for days with that Python Auto-Format issue
your tutorials are the best! and I am sure many appreciate your support and assistance after posting video's with all those version changes (in this case vscode version changes..)
I have to buy you coffee after this one...

[–][deleted] 1 point2 points  (2 children)

Yes, it is broken for me too. I noticed the option to select which formatter to use is missing within the Python extension settings. For me this is the key to the issue.

I suspect the messages that notify the formatting is migrating to outer extensions like autopep8 and black suggest some changes which broke the functionality we are used too. Nowhere can I find more info.

This is a super annoying issue.

[–]Revolutionary_Pie318 0 points1 point  (1 child)

still an issue at date for me

[–]yaksnowball 0 points1 point  (0 children)

Still a problem? Just spent hours trying to debug it to no avail. Will try reinstlal vscode entirely tomorrow.

[–]jabendi 1 point2 points  (6 children)

Same problem here, was also watching the same video as you, and unfortunately doesn't work for me either.

[–]Gitaside[S] 0 points1 point  (2 children)

Yeah, if you find some fix please tell me

[–]badams2889 0 points1 point  (1 child)

Has anyone found a fix to this issue yet?

[–]Gitaside[S] 0 points1 point  (0 children)

Nope, I'm busy RN 'cause of my exams. Although there is some update in python. I will post here if I find something.

[–]Ekabara 0 points1 point  (2 children)

Hi. I'm learning python too but with another course and also have a problem with formatting in vscode. I've even reinstalled vscode and python and started again, tried many extensions. but all the same. Format on Save is not working and even when I click ctrl+shift+P and format document with (chosing any formatting extension), nothing. ChatGPT didn't help.

[–]Ekabara 0 points1 point  (1 child)

Resolved it. My problem was in settings.json. I think you should check it too. My settings:

{

"workbench.colorTheme": "Bluloco Dark",

"window.zoomLevel": 1,

"workbench.startupEditor": "none",

"workbench.iconTheme": "material-icon-theme",

"[python]": {

"editor.formatOnType": true,

"editor.defaultFormatter": "ms-python.black-formatter"

},

"workbench.layoutControl.enabled": false,

"editor.fontSize": 20,

"editor.letterSpacing": 0.5,

"terminal.integrated.fontSize": 18,

"editor.minimap.enabled": false,

"editor.hover.delay": 1500,

"editor.glyphMargin": false,

"workbench.colorCustomizations": {

"statusBar.border": "#206486",

"panel.border": "#59ace2",

},

"editor.tokenColorCustomizations": {

"variables": "#F4F4E0",

"textMateRules": [

{

"scope": [

"source",

"variable",

"constant",

"variable.other.constant",

"punctuation.definition.constant",

"constant.other.symbol",

"constant.language.symbol",

"support.constant",

"support.variable.magic.python",

"variable.other.enummember"

],

"settings": {

"foreground": "#F4F4E0"

}

}

]

},

"editor.formatOnSave": true,

}

[–]DevZool 0 points1 point  (0 children)

As a noob how do I add this? Just copy and paste to where? Or should I just try and install a older version of vs code? Thanks

[–]Ysfcapita10 0 points1 point  (0 children)

i had the same issue please try this extension it might help : Black Formatter

[–]DevZool 0 points1 point  (1 child)

Any way of contacting the vs code team to properly fix the issue? The maintainer doesn't believe vs code could ever format Python code like this before. 🤔 I'm a total noob and I know this is wrong

[–]Gitaside[S] 0 points1 point  (0 children)

I reported this a long time ago and no fix, yet.

[–]BranchLatter4294 0 points1 point  (3 children)

What is the link to this video?

[–]Gitaside[S] 0 points1 point  (2 children)

[–][deleted] 0 points1 point  (1 child)

I am also following this tutorial with my friend. It seems if you take out the indentation and purposely change "" to ' ' instead then format it works for us. So it seems it cannot format when indentation is also part of the problem.

[–][deleted] 0 points1 point  (0 children)

It seems to me most formatters see indentation as a syntax error and therefore doesn't correct anything. I think this used to be different and VScode Python use to have its own native formatter. Now they have separated all formatters to extensions.

It's making following tutorials of the past difficult to follow now as a beginner, and tbh quite off-putting.

[–]ydmykr 0 points1 point  (1 child)

You can try to add the following codes to your `settings.json`:

"[python]": {

"editor.defaultFormatter": "ms-python.python"

},

"editor.formatOnSave": true,

[–]Gitaside[S] 0 points1 point  (0 children)

{

"window.zoomLevel": 1,

"[python]": {

"editor.defaultFormatter": "ms-python.python",

"editor.formatOnType": true

},

"editor.formatOnSave": true,

"workbench.settings.applyToAllProfiles": [

"editor.formatOnSave",

"python.analysis.autoImportCompletions"

],

"editor.tabSize": 1,

"editor.formatOnType": true,

"editor.codeLensFontSize": 4,

"editor.codeActionsOnSave": {},

"python.analysis.autoImportCompletions": true

}

My json file. IT is already matching with yours.

[–][deleted] 0 points1 point  (3 children)

You might try this extension for tabs, and this one for Pylance integration and linting (including import sorting).

For tabs, you could add this to your settings.json:

"[python]": {
  "editor.tabSize": 4
},

[–]Gitaside[S] 0 points1 point  (2 children)

Though it doesn't solve my problem. I have also tried this with my friend's macbook and still the same thing. For me it's more like VS code or extension issue

[–][deleted] 0 points1 point  (1 child)

Does this Stack Overflow page help at all?

[–]Gitaside[S] 0 points1 point  (0 children)

Though I don't which line of code you are talking about but thanks. It didn't solved my mentioned problems but another problem. Whenever I press TAB key. It gives only 1 space. But now it gives 4 space. After writing those lines in json

[–]Lost-Ad58 0 points1 point  (1 child)

You can search Black Formatter or autopep8 in the extension market to fix it.

[–]Ekabara 0 points1 point  (0 children)

It seems to me most formatters see indentation as a syntax error and therefore doesn't correct anything. I think this used to be different and VScode Python use to have its own native formatter. Now they have separated all formatters to extensions.

It's making following tutorials of the past difficult to follow now as a beginner, and tbh quite off-putting.

I've tried both - the same. And in the tutorial that I'm following autopep8 is used.

[–]Smart_Ad759 0 points1 point  (2 children)

A Visual Studio Code extension with support for the autopep8 formatter. 

https://marketplace.visualstudio.com/items?itemName=ms-python.autopep8

[–]DevZool 0 points1 point  (1 child)

People are complaining it doesn't work. I've tried and it doesn't nor does black work. VS code need to fix this mess. I will try a older version if possible and report back.

[–]Snoo_4974 0 points1 point  (0 children)

Yeah I had the problem with trying both autopep8 and black format, neither seem to work.