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

False-positive 'unused-import' for base class name used in type annotation #3191

Closed
saf opened this issue Oct 15, 2019 · 1 comment
Closed
Labels

Comments

@saf
Copy link

saf commented Oct 15, 2019

Starting from pylint 2.4.0, an imported symbol from my own package which is only used in a # type: annotation has been unexpectedly reported as an unused-import.

This works fine with pylint 2.3.1.

Steps to reproduce

mod1/my_types.py:

class Base():
    pass

class Foo(Base):
    pass

class Bar(Base):
    pass

mod1/usage.py:

#!/usr/bin/python3

import sys

from mod1.my_types import Base, Foo, Bar

def main():
    if sys.argv[1:]:
        foo_or_bar = Foo()  # type: Base
    else:
        foo_or_bar = Bar()

    print(foo_or_bar.__class__)


if __name__ == "__main__":
    main()

Current behavior

mod1/usage.py:5: [W0611: unused-import] Unused Base imported from mod1.my_types

Expected behavior

No error reported about the unused import.

pylint --version output

$ python3 -m pylint --version
pylint 2.4.2
astroid 2.3.1
Python 3.6.8 (default, Oct  7 2019, 12:59:55) 
[GCC 8.3.0]
@saf saf changed the title False-positive 'unused-import' for base class name in type annotation False-positive 'unused-import' for base class name used in type annotation Oct 15, 2019
@PCManticore
Copy link
Contributor

Thanks, I can reproduce the issue.

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

No branches or pull requests

2 participants