-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Pylint incorrectly flags as unused-import
things that are used in string literal type annotations
#3299
Comments
I have some additional information related to this issue. Even though there are workarounds by using e.g. from __future__ import annotations there are some type definitions that actually still require you to use string quoting, because typeshed expresses some types as subscriptable generics, e.g. Sadly, every other CQA tool also fails here: pyflakes and pycharm both do not understand this annotation and all three tools have different silencing methods. |
Flake8 can do it for the record, and does not emit an F401 on the example:
|
#4315 also reproduces when the type is a string. |
…teral type annotations (pylint-dev#3299)
… annotations (pylint-dev#7400) Don't emit 'unused-variable' or 'unused-import' on names in string literal type annotations (pylint-dev#3299) Don't treat strings inside typing.Literal as names
Steps to reproduce
pylint_example.py:
pylint_example2.py:
pylint pylint_example2.py
Current behavior
String literal in type annotation is considered "unused" and warning is emitted.
Expected behavior
There should not be any warning about unused import.
pylint --version output
pylint 2.4.4
astroid 2.3.3
Python 3.6.9 (default, Nov 7 2019, 10:44:02)
[GCC 8.3.0]
The text was updated successfully, but these errors were encountered: