Auto indentation level should use black defaults instead of autopep8 #4534
Replies: 13 comments 11 replies
-
Thanks for the issue but this is actually purpose. We follow the indentation rules as outlined in PEP8: This specific example: # Add 4 spaces (an extra level of indentation) to distinguish arguments from the rest.
def long_function_name(
var_one, var_two, var_three,
var_four):
print(var_one) Although we should probably do the same for classes too. If you don't like the auto indent you can turn it off with this setting: "[python]": {
"editor.formatOnType": false,
} Update: There's a new setting to turn off just Pylance's auto indent: "python.analysis.autoIndent": false, |
Beta Was this translation helpful? Give feedback.
-
This particular aspect of function formatting in PEP 8 is pretty archaic at this point. The black format is much more common in modern Python code. You might want to consider changing this behavior. |
Beta Was this translation helpful? Give feedback.
-
As Eric mentioned already, this is rather outdated now. Furthermore, pressing def long_function_name(
var_one: int,
var_two: str,
var_three: float,
var_four: bool,
) -> None:
print(var_one)
I had set that already some time ago. The auto-indent happens anyway on The |
Beta Was this translation helpful? Give feedback.
-
No just doing this should fix the problem: "[python]": {
"editor.formatOnType": false,
} That's the setting that causes our indentation to be called. |
Beta Was this translation helpful? Give feedback.
-
Interesting 🤔 I had set it globally for all languages but that didn't work. Why does the |
Beta Was this translation helpful? Give feedback.
-
Probably a bug in our 'experiment' framework. It sets this to true just for the python language. |
Beta Was this translation helpful? Give feedback.
-
The I can't seem to find a setting that controls that behavior though. |
Beta Was this translation helpful? Give feedback.
-
Moving to a discussion issue for upvotes. |
Beta Was this translation helpful? Give feedback.
-
Not sure if this is related, but it used to be that if you wanted to use a literal multiline string as an argument, the autoindent would try to line up the cursor just after the open-paren, but only on the first line. Subsequent lines would simply maintain the previous line's indentation. Now, it autoindents every line until the string is closed. For example, suppose the first argument is a literal code snippet: cursor.execute("""|) When I press Enter, I get cursor.execute("""
|) OK, fine, it's trying to align with the open-paren. But it used to be that I could just press Backspace to unindent as needed, and then go on typing, with each subsequent line only maintaining the previous line's indentation. For example, after I've unindented and gotten to this point: cursor.execute("""
select * from mytable|) it used to be that pressing Enter would get me to this: cursor.execute("""
select * from mytable
|) But now, I actually get this: cursor.execute("""
select * from mytable
|) Is there a way to go back to just maintaining the previous line's indentation in that situation, without turning off all the other autoindentation, which for the most part is pretty good? |
Beta Was this translation helpful? Give feedback.
-
This seems to be one of the most upvoted discussion at the moment. If the indentation style won't be changed, would you at least consider making it configurable? Side note for PEP 8Others have mentioned it already that most "modern" code doesn't follow it (anymore). I think it's useful to note here that the PEP only describes the style which should be used for the |
Beta Was this translation helpful? Give feedback.
-
This is our 'primary' list I guess you could say of upvoted items: https://github.com/microsoft/pylance-release/discussions?discussions_q=sort%3Atop There's still a bunch on there that we need to finish before anything happens with our format on type indentation. Having a setting for mode might be a good idea. I'm wary of which one we pick. Should it be black? Should it be prettier? Shouldn't we not pick anything and let another extension do formatting if you don't like our default? I believe that's why we have pep8 as our default now. |
Beta Was this translation helpful? Give feedback.
-
Maybe we just need a more obvious setting to turn our formatting off. This one seems wrong because other extensions wouldn't be able to implement format on type: "[python]": {
"editor.formatOnType": false
}, |
Beta Was this translation helpful? Give feedback.
-
I don't think the Pylance extension should be implementing 'black' formatting for format on type. The black extension should. |
Beta Was this translation helpful? Give feedback.
-
Environment data
Code Snippet
Repro Steps
Expected behavior
The cursor should only auto-indent 4 spaces / one level. This was the behavior up until pylance
2023.4.30
.It's also what
black
uses when it formats code.An indentation of 8 spaces is only used when the closing parentheses isn't on a new line.
Screen.Recording.2023-06-21.at.11.18.43.mov
https://black.readthedocs.io/en/stable/the_black_code_style/current_style.html#how-black-wraps-lines
Actual behavior
The cursor is moved to an indentation level of 8 spaces.
Screen.Recording.2023-06-21.at.11.17.24.mov
Of note: Adding class parameter still only indents to 4 spaces.
Screen.Recording.2023-06-21.at.11.23.07.mov
Logs
--
Beta Was this translation helpful? Give feedback.
All reactions