Skip to content

False positive when member name matches a type name in quoted annotation #2644

@ThomasBendaSEL

Description

@ThomasBendaSEL

Describe the bug
When a type annotation is an exact string match for a class name defined elsewhere in the file, it is falsely reported as a circular reference.

To Reproduce
See code below for a minimal repro case.

Expected behavior
PEP-0563 indicates that I should expect that the type hint would only match names in the module scope.

See https://www.python.org/dev/peps/pep-0563/#implementation

Screenshots or Code

class A:
    A: 'str'

class B:
    A: 'A'

The above code produces the following error:

bad_match.py:5:9 - error: Type of "A" could not be determined because it refers to itself (reportGeneralTypeIssues)

This should correctly evaluate to class A rather than the class member A

VS Code extension or command-line

Running pyright 1.1.191 on the command line.

Additional context
None

Metadata

Metadata

Assignees

No one assigned

    Labels

    addressed in next versionIssue is fixed and will appear in next published versionbugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions