autoflake
autoflake copied to clipboard
Add option to keep the useless passes
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
There seem to be test failures that result from this change.
https://travis-ci.org/myint/autoflake/builds/84375491
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
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.
Can this be fixed up?
I have the last version and it is still removing the pass
making syntax errors
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, I think the problem mentioned in https://github.com/myint/autoflake/pull/9#issuecomment-146725843 would need to be resolved first.
@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, 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
And I can find many more similar errors by running the acid test for about a minute.
$ ./test_acid.py
@alvarotroya do you have any interest in porting your changes in fsouza/autoflake8#70? If not, I can do it.
@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 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