Class scope name resolution issue
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) # Incorrectly reveals int, should be Optional[int]
reveal_type(y) # Correctly reveals int
x = 2
I also found https://bugs.python.org/issue24129 interesting. Thanks, ilevkivskyi!
Hello,
Can you assign this issue to me, please?
we don't assign issues, just open the PR!
Hi! I’ve been working on this issue, but I’d like to check if I’m on the right track.
At first, I misunderstood where the problem was happening, and I made some changes in scope.py. Later I realized that this file only manages the current target scope, and not the name resolution logic itself.
I’m now exploring checkexpr.py (especially visit_name_expr and analyze_ref_expr) and checker.py, since that seems to be where the actual name resolution and type checking happen.
Could you please confirm if I’m heading in the right direction, or give me any guidance on which part of the code would be best to focus on for this issue?
Thanks a lot ! I’m still getting familiar with mypy’s internals, so any advice would be super helpful
Will need a change in semanal.py I think!