Open PhilipYip1988 opened 1 year ago
Hey @PhilipYip1988, thanks for reporting. You said:
From what I understand black is an opinionated formatter that formats code using autopep8 and then applies its opinions.
That is not correct. Each one is a different formatter and doesn't depend on the other to do its job.
However, we could offer menu entries to format a file with different formatters, so users can get the result you posted above in case they are not happy with a single formatter.
Thanks, it seems like I misunderstood how Black worked. Looking at this in more detail, it seems Black is missing some features found in AutoPEP8.
Despite Black stating it is PEP 8 compliant:
Black is a PEP 8 compliant opinionated formatter with its own style.
It seems it ignores the following PEP 8 guidelines on imports and doesn't do anything to library imports:
Imports should be grouped in the following order:
Standard library imports. Related third party imports. Local application/library specific imports. You should put a blank line between each group of imports.
This seems to have been a requested feature with 93 comments which finally ended up being rejected:
Optimize Imports #333 Not Planned.
And therefore Spyder is implementing Black properly and the above issue is an inherent limitation in Black itself. I also get the same results running Black using the command line.
Having the ability to run AutoPEP8 and then Black in succession from the menu as you suggested will be the best implementation giving features from both.
Format with black should format with autopep8 and then format with black
What steps reproduce the problem?
Sloppy example code:
What is the expected output? What do you see instead?
From what I understand black is an opinionated formatter that formats code using autopep8 and then applies its opinions. In Spyder, the intermediate step format with autopep8 is not carried out when format with black is used.
Example code -> format with black:
This doesn't look right...
Example code -> format with autopep8
This looks right.
Example code -> format with autopep8 -> format with black:
This looks right.
Example code -> format with autopep8 -> format with black -> format with blue
Format with blue not currently supported should theoretically look like this.
Versions
Dependencies