autoflake icon indicating copy to clipboard operation
autoflake copied to clipboard

Add option to keep the useless passes

Open jobevers opened this issue 8 years ago • 10 comments

Adds a --keep-useless-pass argument to the CLI.

Also had to change the behavior that replaces a removed import with pass to return None instead and filter out Nones

jobevers avatar Oct 08 '15 19:10 jobevers

There seem to be test failures that result from this change.

https://travis-ci.org/myint/autoflake/builds/84375491

myint avatar Oct 08 '15 23:10 myint

I don't think this change works in general. For example, in the case of codecs.py, it introduces a syntax error. Note the conditional is left hanging without a body.

$ ./autoflake.py /opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/codecs.py
--- original//opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/codecs.py
+++ fixed//opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/codecs.py
@@ -393,7 +393,6 @@
             stream to recover state.

         """
-        pass

     def seek(self, offset, whence=0):
         self.stream.seek(offset, whence)
@@ -1098,7 +1097,6 @@
 # package
 _false = 0
 if _false:
-    import encodings

 ### Tests

myint avatar Oct 09 '15 00:10 myint

Ah. Thanks. I figured there was a reason behind replacing the import with a pass and then cleaning up the passes.

I'll take a second shot at it shortly.

jobevers avatar Oct 09 '15 04:10 jobevers

Can this be fixed up?

krisdestruction avatar Sep 08 '16 00:09 krisdestruction

I have the last version and it is still removing the pass making syntax errors

chinomng avatar Oct 13 '16 19:10 chinomng

I tried this branch with

pip install -e git+https://github.com/jobevers/autoflake#egg=autoflake

and it works as it's expected: leaving the pass statement.

I would like to have this merged into master.

humitos avatar Oct 24 '16 17:10 humitos

@humitos, I think the problem mentioned in https://github.com/myint/autoflake/pull/9#issuecomment-146725843 would need to be resolved first.

myint avatar Oct 25 '16 02:10 myint

@myint I think it's already fixed:

$ autoflake /usr/lib/python3.5/codecs.py
--- original//usr/lib/python3.5/codecs.py
+++ fixed//usr/lib/python3.5/codecs.py
@@ -393,7 +393,6 @@
             stream to recover state.

         """
-        pass

     def seek(self, offset, whence=0):
         self.stream.seek(offset, whence)

Using the option added in that PR:

$ autoflake --keep-useless-pass /usr/lib/python3.5/codecs.py
$

humitos avatar Oct 25 '16 03:10 humitos

@humitos, I still get the original error.

I've put my codecs.py here.

$ git clone https://github.com/jobevers/autoflake
$ cd autoflake

$ shasum /opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/codecs.py
7f121cb19f206da053d41d3850ebb2a884fd60ff  /opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/codecs.py

$ ./autoflake.py /opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/codecs.py
--- original//opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/codecs.py
+++ fixed//opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/codecs.py
@@ -393,7 +393,6 @@
             stream to recover state.

         """
-        pass

     def seek(self, offset, whence=0):
         self.stream.seek(offset, whence)
@@ -1098,7 +1097,6 @@
 # package
 _false = 0
 if _false:
-    import encodings

 ### Tests

myint avatar Oct 25 '16 13:10 myint

And I can find many more similar errors by running the acid test for about a minute.

$ ./test_acid.py

myint avatar Oct 25 '16 13:10 myint

@alvarotroya do you have any interest in porting your changes in fsouza/autoflake8#70? If not, I can do it.

fsouza avatar Sep 18 '22 02:09 fsouza

@alvarotroya do you have any interest in porting your changes in fsouza/autoflake8#70? If not, I can do it.

Hi @fsouza, thank you for the ping! I can definitely do it, if I remember correctly I already did this on a local branch but was missing the tests. I’ll take care of this and start a PR.

alvarotroya avatar Sep 18 '22 06:09 alvarotroya

@alvarotroya do you have any interest in porting your changes in fsouza/autoflake8#70? If not, I can do it.

Hi @fsouza, thank you for the ping! I can definitely do it, if I remember correctly I already did this on a local branch but was missing the tests. I’ll take care of this and start a PR.

PR started here: https://github.com/PyCQA/autoflake/pull/143

alvarotroya avatar Sep 18 '22 20:09 alvarotroya