autoflake icon indicating copy to clipboard operation
autoflake copied to clipboard

Add `populate_all` feature

Open adhikasp opened this issue 7 years ago • 11 comments

This add --populate-all optional argument to populate (append if exist or create it) __all__ variables with unused modules found in the code.

Closes https://github.com/myint/autoflake/issues/16

adhikasp avatar Aug 29 '17 02:08 adhikasp

Coverage Status

Coverage decreased (-0.3%) to 97.908% when pulling 1afce1ba61891155c6f93672e7b19b6296bebb4a on adhikasp:all into 459f5f53cf10109020fce0470b1cd456d4bfec46 on myint:master.

coveralls avatar Aug 29 '17 02:08 coveralls

Coverage Status

Coverage decreased (-0.05%) to 98.17% when pulling ad4eff0cb0012064882ab78ebc4ec120bb0401a9 on adhikasp:all into 459f5f53cf10109020fce0470b1cd456d4bfec46 on myint:master.

coveralls avatar Aug 29 '17 02:08 coveralls

Thanks!

I tried this out in a file like:

from foo import bar as alpha, beta
$ ./autoflake.py --pop __init__.py
--- original/__init__.py
+++ fixed/__init__.py
@@ -1 +1,2 @@
 from foo import bar as alpha, beta
+__all__ = ['bar as alpha', 'beta']

And I got an interesting module name. 😄

myint avatar Aug 31 '17 02:08 myint

Weird, i test as too yesterday and it works :/ Will look into it.

On Thu, 31 Aug 2017, 09:07 Steven Myint [email protected] wrote:

Thanks!

I tried this out in a file like:

from foo import bar as alpha, beta

$ ./autoflake.py --pop init.py --- original/init.py +++ fixed/init.py @@ -1 +1,2 @@ from foo import bar as alpha, beta +all = ['bar as alpha', 'beta']

And I got an interesting module name. 😄

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/myint/autoflake/pull/26#issuecomment-326168675, or mute the thread https://github.com/notifications/unsubscribe-auth/AF3chnXUcDjN1Hr7UeREnsgyrhOBzHWqks5sdhVJgaJpZM4PFTU5 .

-- Regards

Adhika Setya Pramudita Undergraduate student of Information Technology University of Gadjah Mada Yogyakarta

Web: http://adhikasetyap.me LinkedIn http://id.linkedin.com/in/adhikasp

adhikasp avatar Aug 31 '17 02:08 adhikasp

Thanks. You might also want to test imports with tabs in the code:

from alpha import beta<tab>as<tab>gamma

myint avatar Sep 01 '17 01:09 myint

Coverage Status

Coverage increased (+0.09%) to 98.312% when pulling 27a89d9642dd95422d26c86f37769108875276d5 on adhikasp:all into 459f5f53cf10109020fce0470b1cd456d4bfec46 on myint:master.

coveralls avatar Sep 04 '17 04:09 coveralls

Looks good. I found one other edge case. Files like the following, get an empty __all__ added to them.

def foo():
    bar = 0
--- original/foo.py
+++ fixed/foo.py
@@ -1,2 +1,3 @@
 def foo():
     bar = 0
+__all__ = []

myint avatar Sep 04 '17 18:09 myint

I guess the other thing I notice from the above is that this new feature affects all files. I think we should be conservative and only touch __init__.py files. This follows https://github.com/myint/autoflake/issues/16#issuecomment-317932366.

myint avatar Sep 04 '17 18:09 myint

Coverage Status

Coverage increased (+0.1%) to 98.32% when pulling 310e1a372986ce951f6d1be24544bb02b23b0309 on adhikasp:all into 459f5f53cf10109020fce0470b1cd456d4bfec46 on myint:master.

coveralls avatar Oct 08 '17 19:10 coveralls

Coverage Status

Coverage increased (+0.1%) to 98.32% when pulling 7b2b5ae1c361fe3ff089d86ca3b0461707cecf5b on adhikasp:all into 459f5f53cf10109020fce0470b1cd456d4bfec46 on myint:master.

coveralls avatar Oct 08 '17 19:10 coveralls

@adhikasp do you still plan to work on this?

fsouza avatar Sep 18 '22 02:09 fsouza