Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to keep the useless passes #9

Closed
wants to merge 1 commit into from

Conversation

jobevers
Copy link

@jobevers jobevers commented Oct 8, 2015

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

@myint
Copy link
Member

myint commented Oct 8, 2015

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

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

@myint
Copy link
Member

myint commented Oct 9, 2015

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

@jobevers
Copy link
Author

jobevers commented Oct 9, 2015

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.

myint added a commit that referenced this pull request Oct 9, 2015
This relates to #9.
@krisdestruction
Copy link

Can this be fixed up?

@chinomng
Copy link

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

@humitos
Copy link

humitos commented Oct 24, 2016

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.

@myint
Copy link
Member

myint commented Oct 25, 2016

@humitos, I think the problem mentioned in #9 (comment) would need to be resolved first.

@humitos
Copy link

humitos commented Oct 25, 2016

@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
$

@myint
Copy link
Member

myint commented Oct 25, 2016

@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
Copy link
Member

myint commented Oct 25, 2016

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

$ ./test_acid.py

@fsouza
Copy link
Collaborator

fsouza commented Sep 18, 2022

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

@alvarotroya
Copy link
Contributor

@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
Copy link
Contributor

@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: #143

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants