Skip to content

Figure out how to detect unused imports #865

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

Closed
JukkaL opened this issue Aug 30, 2015 · 8 comments
Closed

Figure out how to detect unused imports #865

JukkaL opened this issue Aug 30, 2015 · 8 comments

Comments

@JukkaL
Copy link
Collaborator

JukkaL commented Aug 30, 2015

Linters like flake8 can detect unused imports, but this actually doesn't work with PEP 484 compliant code, as some of the uses can be in comments that are not seen by the linter. For example:

from typing import List   # 'List' imported but unused 
x = []  # type: List[int]

We should either try to get linters fixed (file issues) or allow mypy to detect these kinds of errors reliably.

@JukkaL JukkaL added the task label Aug 30, 2015
@o11c
Copy link
Contributor

o11c commented Aug 31, 2015

Not just unused imports, but all unused variables (that do not start with _).

I think it's best to make mypy do this, controlled via a -W option. But rewriting the parser is going slower than I expected, I keep restarting when I see a better way ...

Related: #465

@pradyunsg
Copy link
Member

What needs to be done to help move this forward?

@ilevkivskyi
Copy link
Member

What needs to be done to help move this forward?

Make a PR (assuming you are confident enough, since this might be not a small change).

@ilevkivskyi
Copy link
Member

(Btw, latest versions of popular linters already understand/will soon understand type comments).

@pradyunsg
Copy link
Member

Make a PR (assuming you are confident enough, since this might be not a small change).

Any pointers for where to get started on this?

(Btw, latest versions of popular linters already understand/will soon understand type comments).

Oh, is this due to the work on typed-ast, which would get adopted by the linters?

@gvanrossum
Copy link
Member

gvanrossum commented May 27, 2018 via email

@emmatyping
Copy link
Member

I believe linters now can detect PEP 484 type comments without issue (see e.g. PyCQA/pyflakes#400), so I think we can close this?

@jdahlin
Copy link
Contributor

jdahlin commented Mar 22, 2021

Would be nice if mypy could support this, its one less tool is needed to lint a code base.

This doesn't seem possible with the current plugin API, perhaps extending the plugin API to expose enough information to make this possible in third-party code would be good enough.

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

No branches or pull requests

8 participants