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

[FEATURE] Add scope analiythis #167

Open
Bobronium opened this issue Aug 29, 2022 · 0 comments
Open

[FEATURE] Add scope analiythis #167

Bobronium opened this issue Aug 29, 2022 · 0 comments
Labels
enhancement New feature or request feature New things

Comments

@Bobronium
Copy link

Bobronium commented Aug 29, 2022

Thesis

pycln should perform scope analythis and remove unused imports accordingly.

Reasoning

This would be consistent with flake8, pylance and PyCharms behaviour in identifying unused imports.

autoflake and unimport are able to remove them as well

image

cat test.py

import sys

def func():
    import sys

    def inner():
        import sys

        sys.exit(0)

pycln

$ pycln test.py                 
Looks good! ✨ 🍰 ✨
1 file left unchanged.

autoflake

$ autoflake test.py                                                  
--- original/test.py
+++ fixed/test.py
@@ -1,8 +1,7 @@
-import sys
 
 
 def func():
-    import sys
+    pass
 
     def inner():
         import sys

unimport

$ unimport -d test.py           
--- test.py

+++ 

@@ -1,8 +1,6 @@

-import sys
 
 
 def func():
-    import sys
 
     def inner():
         import sys
@Bobronium Bobronium added enhancement New feature or request feature New things labels Aug 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request feature New things
Projects
None yet
Development

No branches or pull requests

1 participant