python / python/mypy

New semantic analyzer: placeholder nodes from self.x assignment

Open
#6,338 0 comments 0 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.