asottile/dead

importing a symbol without using it marks it as used

Tadaboody opened this issue · 4 comments

# foo.py
def foo(): ...
# bar.py
from foo import foo # Imported but unused
$ dead
# Dead silence, even if you commit foo.py and bar.py

From what I've looked this seems like intended behavior - why? is there a false positive corner case I'm missing?
https://github.com/asottile/dead/blob/master/dead.py#L50
And if it is intended I'd like a configuration value to change it

I think the edgecase I ran into was something like

# foo.py
def foo(): ...
# bar.py
from foo import foo as foo_func

foo_func()

this was marking foo as unused, though it was definitely used.

Maybe it should only do that behaviour when using as?

Though shouldn't pyflakes / flake8 catch that case?

pyflakes would catch the unused import, but not the dead code that is foo.
running flake8, deleting the import and then running dead again would solve it but that seems cumbersome when I think dead can easily do it

dead already kinda assumes you'll run it each time you delete code 🤷‍♂️ there's no recursive unused support right now

closing this as wontfix -- the suggestion being to use pyflakes/flake8 to detect "imported but unused" within a file