hhatto / autopep8

A tool that automatically formats Python code to conform to the PEP 8 style guide.
https://pypi.org/project/autopep8/
MIT License
4.54k stars 291 forks source link

How to ignore the two-spaces-before-comment rule ? #722

Closed Gouvernathor closed 2 months ago

Gouvernathor commented 6 months ago

I'm using the autopop8 extension on VSCode. Using the extension settings, I was successfully able to deactivate some of the toggles I don't like (such as E301 or E302) and to enable verbose mode. The verbose mode states in the console that it finds the E261 error at lines 163, 85 and 110, lines which consist of code followed by a comment with one space between the code and the comment. I'm deducing that this is rule E261, and that's the one I want to disable. But adding E261 to the list of --ignore doesn't change anything, a second space keeps getting added when I format the file. E261 is not listed in the features, the closest one is E26, but adding that one doesn't change anything either.

Python Code


class CardinalVote(VotingMethod):
    __slots__ = ("grades",) # the number of different grades, >1
    return_format = results_format.SCORES
    name = "Score Vote"

Command Line and Configuration

.pep8, setup.cfg, ...

image

Your Environment

hhatto commented 3 months ago

It works fine in my environment. If I change the --ignore option to "E26,E301,E302,E303,E305" instead of [E26,E301,E302,E303,E305], does it not work? I think you don't need the [] brackets.

$ pycodestyle --version
2.11.1

$ autopep8 --version
autopep8 1.6.0 (pycodestyle: 2.8.0)

$ python -V
Python 3.11.6

$ cat example.py
class CardinalVote(VotingMethod):
    __slots__ = ("grades",) # the number of different grades, >1
    return_format = results_format.SCORES
    name = "Score Vote"

$ pycodestyle example.py
example.py:2:28: E261 at least two spaces before inline comment

$ pycodestyle --ignore=E26,E301,E302,E303,E305 example.py

$ autopep8 -d example.py
--- original/example.py
+++ fixed/example.py
@@ -1,4 +1,4 @@
 class CardinalVote(VotingMethod):
-    __slots__ = ("grades",) # the number of different grades, >1
+    __slots__ = ("grades",)  # the number of different grades, >1
     return_format = results_format.SCORES
     name = "Score Vote"

$ autopep8 --ignore=E26,E301,E302,E303,E305 -d example.py

$ autopep8 --ignore="[E26,E301,E302,E303,E305]" -d example.py
--- original/example.py
+++ fixed/example.py
@@ -1,4 +1,4 @@
 class CardinalVote(VotingMethod):
-    __slots__ = ("grades",) # the number of different grades, >1
+    __slots__ = ("grades",)  # the number of different grades, >1
     return_format = results_format.SCORES
     name = "Score Vote"