Skip to content

Referencing name not defined yet allowed by mypy, yet error at runtime. #17610

@MarioIshac

Description

@MarioIshac

To Reproduce

from collections.abc import Callable

class A:
    @staticmethod
    def b(c: Callable[[], None]) -> Callable[[], None]:
        return c
    
    @A.b
    @staticmethod
    def c() -> None:
        pass

mypy playground

Expected Behavior

Invoking mypy catches error.

Actual Behavior

Success: no issues found in 1 source file

However, at runtime:

NameError: name 'A' is not defined

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions