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.58k stars 291 forks source link

Allow disabling extended blank lines check #431

Open benjaminjkraft opened 6 years ago

benjaminjkraft commented 6 years ago

It would be nice to have an option to disable all of the features where autopep8 goes beyond what pycodestyle requires. This is useful for avoiding spurious diffs when operating on existing codebases which don't necessarily follow those rules. Right now, they can only be disabled by disabling all the E301/E303 fixes, which is unfortunate.

hhatto commented 6 years ago

Hi,

Now how do you specify options and if you change, for example, what options should I have?

benjaminjkraft commented 6 years ago

For my purposes any of the following would work great:

hhatto commented 6 years ago

autopep8 is correcting according to pycodestyle's error codes. Currently there are some to fix with lib2to3.

all of the features where autopep8 goes beyond what pycodestyle requires.

Specifically, what kind of correction is it? I would appreciate it if you have code examples.

benjaminjkraft commented 6 years ago

The corrections I refer to are the ones here: https://github.com/hhatto/autopep8/blob/master/autopep8.py#L187 which are using the same error code as pycodestyle but making different changes.

Here's a sample file:

# test.py
class Foo:
    """docstring"""
    def bar(self):
        pass

Running flake8 test.py returns no warnings, but autopep8 still tries to make changes:

$ autopep8 -d test.py
--- original/test.py
+++ fixed/test.py
@@ -1,5 +1,6 @@
 # test.py
 class Foo:
     """docstring"""
+
     def bar(self):
         pass