generic with union value inferred as common base
Open
Nobody has claimed this yet.
bug
topic-join-v-union
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
from typing import _T
class A:...
class B(A):
a: int
class C(A):
a: int
def safe(it: _T | None) -> _T:...
b_or_c: B | C
value = safe(b_or_c)
reveal_type(value) #A, should be B | C
value.a # error
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 revealed type in the linked mypy-play example, then locate the generic inference and union-handling tests or entry points in mypy. Add a regression test for safe(B | C) preserving B | C, and verify that value.a is accepted.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100