autoflake
autoflake copied to clipboard
Add `populate_all` feature
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
Coverage decreased (-0.3%) to 97.908% when pulling 1afce1ba61891155c6f93672e7b19b6296bebb4a on adhikasp:all into 459f5f53cf10109020fce0470b1cd456d4bfec46 on myint:master.
Coverage decreased (-0.05%) to 98.17% when pulling ad4eff0cb0012064882ab78ebc4ec120bb0401a9 on adhikasp:all into 459f5f53cf10109020fce0470b1cd456d4bfec46 on myint:master.
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. 😄
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
Thanks. You might also want to test imports with tabs in the code:
from alpha import beta<tab>as<tab>gamma
Coverage increased (+0.09%) to 98.312% when pulling 27a89d9642dd95422d26c86f37769108875276d5 on adhikasp:all into 459f5f53cf10109020fce0470b1cd456d4bfec46 on myint:master.
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__ = []
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.
Coverage increased (+0.1%) to 98.32% when pulling 310e1a372986ce951f6d1be24544bb02b23b0309 on adhikasp:all into 459f5f53cf10109020fce0470b1cd456d4bfec46 on myint:master.
Coverage increased (+0.1%) to 98.32% when pulling 7b2b5ae1c361fe3ff089d86ca3b0461707cecf5b on adhikasp:all into 459f5f53cf10109020fce0470b1cd456d4bfec46 on myint:master.
@adhikasp do you still plan to work on this?