Skip to content

Pylint incorrectly flags as unused-import things that are used in string literal type annotations #3299

Closed
@sanyassh

Description

@sanyassh

Steps to reproduce

pylint_example.py:

class Class:
    pass

pylint_example2.py:

from pylint_example import Class


class Class2:
    cls: 'Class'

pylint pylint_example2.py

************* Module pylint_example2
pylint_example2.py:4:0: R0903: Too few public methods (0/2) (too-few-public-methods)
pylint_example2.py:1:0: W0611: Unused Class imported from pylint_example (unused-import)

------------------------------------------------------------------
Your code has been rated at 3.33/10 (previous run: 3.33/10, +0.00)

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]

Metadata

Metadata

Assignees

No one assigned

    Labels

    False Positive 🦟A message is emitted but nothing is wrong with the codeGood first issueFriendly and approachable by new contributorsHacktoberfestHelp wanted 🙏Outside help would be appreciated, good for new contributorsNeeds PRThis issue is accepted, sufficiently specified and now needs an implementation

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions