Skip to content

Class scope name resolution issue #9991

Open
@hauntsaninja

Description

@hauntsaninja

Example courtesy of @gvanrossum , based on https://twitter.com/gvanrossum/status/1354305179244392453

While Python's behaviour is surprising, mypy should match it.

from typing import *

x: Optional[int] = None
y: Optional[int] = None

def f() -> None:
    x = 1
    y = 1
    class C:
        reveal_type(x)  # Correctly reveals int
        reveal_type(y)  # Incorrectly reveals int, should be Optional[int]
        x = 2

I also found https://bugs.python.org/issue24129 interesting. Thanks, ilevkivskyi!

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions