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

unused-import false positive for a module used in a type comment #4603

Closed
superbobry opened this issue Jun 22, 2021 · 0 comments · Fixed by #4604
Closed

unused-import false positive for a module used in a type comment #4603

superbobry opened this issue Jun 22, 2021 · 0 comments · Fixed by #4604
Labels
Enhancement ✨ Improvement to a component False Positive 🦟 A message is emitted but nothing is wrong with the code

Comments

@superbobry
Copy link
Contributor

Steps to reproduce

"""Docstring."""

import abc
from abc import ABC

X = ...  # type: abc.ABC
Y = ...  # type: ABC

Current behavior

************* Module a
/tmp/a.py:3:0: W0611: Unused import abc (unused-import)

-----------------------------------
Your code has been rated at 7.50/10

Expected behavior

unused-import should not be emitted.

pylint --version output

Result of pylint --version output:

pylint 2.8.3
astroid 2.5.6
Python 3.9.2 (default, Feb 28 2021, 17:03:44) 
[GCC 10.2.1 20210110]

This is a follow up to #3112.

superbobry added a commit to superbobry/pylint that referenced this issue Jun 22, 2021
superbobry added a commit to superbobry/pylint that referenced this issue Jun 22, 2021
Prior to this commit VariableChecker did not recurse into attribute lookups
in type comments. This lead to false positive unused-import messages in e.g.

    import collections
    d = ...  # type: collections.OrderedDict

Fixes pylint-dev#4603.
@Pierre-Sassoulas Pierre-Sassoulas added Enhancement ✨ Improvement to a component False Positive 🦟 A message is emitted but nothing is wrong with the code labels Jun 22, 2021
superbobry added a commit to superbobry/pylint that referenced this issue Jun 23, 2021
Prior to this commit VariableChecker did not recurse into attribute lookups
in type comments. This lead to false positive unused-import messages in e.g.

    import collections
    d = ...  # type: collections.OrderedDict

Fixes pylint-dev#4603.
superbobry added a commit to superbobry/pylint that referenced this issue Jun 26, 2021
Prior to this commit VariableChecker did not recurse into attribute lookups
in type comments. This lead to false positive unused-import messages in e.g.

    import collections
    d = ...  # type: collections.OrderedDict

Fixes pylint-dev#4603.
superbobry added a commit to superbobry/pylint that referenced this issue Jun 26, 2021
Prior to this commit VariableChecker did not recurse into attribute lookups
in type comments. This lead to false positive unused-import messages in e.g.

    import collections
    d = ...  # type: collections.OrderedDict

Fixes pylint-dev#4603.
superbobry added a commit to superbobry/pylint that referenced this issue Jun 27, 2021
Prior to this commit VariableChecker did not recurse into attribute lookups
in type comments. This lead to false positive unused-import messages in e.g.

    import collections
    d = ...  # type: collections.OrderedDict

Fixes pylint-dev#4603.
Pierre-Sassoulas pushed a commit that referenced this issue Jun 27, 2021
…4604)

* VariableChecker now accounts for attribute lookups in type comments

Prior to this commit VariableChecker did not recurse into attribute lookups
in type comments. This lead to false positive unused-import messages in e.g.

    import collections
    d = ...  # type: collections.OrderedDict

Fixes #4603
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement ✨ Improvement to a component False Positive 🦟 A message is emitted but nothing is wrong with the code
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants