Skip to content

undefined-variable false positive when method returns instance type when the class is inside a function  #8145

Open
@DetachHead

Description

@DetachHead

Bug description

from __future__ import annotations

def foo():
    class Foo:
        def foo(self) -> Foo:  # E0602:undefined-variable
            ...

class Bar:
    def foo(self) -> Bar:  # no error
        ...

Configuration

No response

Command used

pylint a.py

Pylint output

************* Module a       
a.py:6:25: E0602: Undefined variable 'Foo' (undefined-variable)  

-----------------------------------

Expected behavior

no error

Pylint version

pylint 2.16.0b1
astroid 2.14.0-dev0
Python 3.11.1 (tags/v3.11.1:a7a450f, Dec  6 2022, 19:58:39) [MSC v.1934 64 bit (AMD64)]

OS / Environment

No response

Additional dependencies

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    C: undefined-variableIssues related to 'undefined-variable' checkFalse Positive 🦟A message is emitted but nothing is wrong with the codeNeeds PRThis issue is accepted, sufficiently specified and now needs an implementation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions