microsoft / microsoft/pyright

Incorrect scope lookup in class bodies in 3.14

Open
#10,808 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Python
Stars
15.6k
Forks
1.8k
Avg merge
12h 13m
Merged PRs (30d)
52

Description

I noticed in the conformance tests (https://github.com/python/typing/issues/2069) that pyright in Python 3.14 incorrectly resolves names in annotations in class scopes.

```python
from typing import reveal_type

class X:
def int(self): pass

f: int # expect error

class str: pass

g: str

def method(self):
reveal_type(self.f) # get int, expect Any
reveal_type(self.g + "") # get str, expect an error (X.str + "" is not allowed)
```

https://pyright-play.net/?pythonVersion=3.14&strict=true&enableExperimentalFeatures=true&code=GYJw9gtgBALgngBwJYDsDmUkQWEMogCmAboQIYA2A%2BvAoQFCMDGFZAzm1ABoBc9UAqABNCwTChgAKNoQrAAlDygJ2bRoKjAlqfFADEUQgA86TfIRDgQ6wS1VQ2MEEpUcbAtEsfX%2BgkWIhCGAALMCFpWQU%2BDQ0iUkoaREIIuQA6BQEDNCDxGAAaQxNCMygAQRQ4XxiCEnJqWmSZNIwAaigAInb5TKhs-G8C41N8MhRDS1woSS5U7yg2zsxOFDARigowAHdCIXl6IA

Name lookups in annotations within class bodies should behave like name lookups in the class body itself, except that the lookup happens only after the class body has fully executed, so names can be used before they are defined. This is in line with the runtime behavior.

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the examples in the linked pyright playground with Python 3.14, strict mode, and experimental features enabled. Compare the reported types and errors with the stated class-body lookup rules and the runtime behavior, then trace the name-resolution path for annotations in class scopes. Done means the examples resolve names consistently with those rules and the relevant conformance behavior passes.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
compilers, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.