Skip to content

undefined-variable on correct return type hints #3461

Closed
@craynic

Description

@craynic

Steps to reproduce

code:

from enum import Enum


class Right:
    class Result1(Enum):
        OK = 0
    def work(self) -> Result1:
        return self.Result1.OK


class Wrong:
    class Result2(Enum):
        OK = 0
    def work(self) -> self.Result2:
        return self.Result2.OK

Got an error in running:

Traceback (most recent call last):
  File "tmp.py", line 11, in <module>
    class Wrong:
  File "tmp.py", line 14, in Wrong
    def work(self) -> self.Result2:
NameError: name 'self' is not defined

Current behavior

tmp.py:7:22: E0602: Undefined variable 'Result1' (undefined-variable)

Expected behavior

tmp.py:14:22: E0602: Undefined variable 'self' (undefined-variable)

pylint --version output

pylint 2.4.4
astroid 2.3.3
Python 3.8.2 (default, Feb 26 2020, 22:21:03)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions