New semantic analyzer: placeholder nodes from self.x assignment
Open
Nobody has claimed this yet.
bug
priority-1-normal
semantic-analyzer
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
This test case generates unexpected output:
class C:
def f(self) -> None:
self.x: D = D() # Expression has type "D", variable has type "int"
self.x: int
class D: pass
reveal_type(C().x) # int
The first assignment should take precedence, even though it contains a forward reference. We could probably support this by inserting a placeholder node into the class symbol table.
Follow-up to #6336.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the provided Python example and inspect the semantic analyzer's handling of class symbol tables and forward references. Investigate whether a placeholder node can preserve the first self.x assignment. Done means the example no longer reports the conflicting type error and reveal_type(C().x) reports int.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100