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.56k stars 290 forks source link

E266 cannot be ignored on its own #649

Closed PeterJCLaw closed 1 year ago

PeterJCLaw commented 1 year ago

Python Code

### Block marker
################

#This comment needs a space

foo = '' #This comment needs a space

Command Line and Configuration

Command Line

$ autopep8 --diff demo.py --ignore E266

Actual:

--- original/demo.py
+++ fixed/demo.py
@@ -1,6 +1,6 @@
-### Block marker
+# Block marker
 ################

-#This comment needs a space
+# This comment needs a space

-foo = '' #This comment needs a space
+foo = ''  # This comment needs a space

Desired:

--- original/demo.py
+++ fixed/demo.py
@@ -1,6 +1,6 @@
 ### Block marker
 ################

-#This comment needs a space
+# This comment needs a space

-foo = '' #This comment needs a space
+foo = ''  # This comment needs a space

In comparison:

$ autopep8 --diff demo.py --ignore E26

(suggested at https://github.com/hhatto/autopep8/issues/78#issuecomment-18908780) outputs no change at all, yet I do want the other comments to be fixed so this doesn't work for me.

The same issue applies when specifying E266 via setup.cfg too, so I'm assuming this isn't just a CLI parsing issue.

Your Environment