Inconsistent Any matching with Overloads in TypeGuard/TypeIs
Open
Nobody has claimed this yet.
bug
topic-overloads
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
Bug Report
There is an inconsistency left where currently TypeIs/TypeGuard narrows in case of multi-Any matches, while this is not done in normal overloads. I find this strange and would prefer that it is consistent.
To Reproduce
@overload
def func1(x: str) -> TypeIs[str]:
...
@overload
def func1(x: int) -> TypeIs[int]:
...
def func1(x: Any) -> Any:
return True
def func2(val: Any):
if func1(val):
reveal_type(val) # Currently int | str
@overload
def func3(x: str) -> str:
...
@overload
def func3(x: int) -> int:
...
def func3(x: Any) -> Any:
return True
def func4(val: Any):
reveal_type(func3(val)) # Currently Any
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 running the linked Playground reproduction with mypy 1.15 or the latest version, comparing TypeIs/TypeGuard narrowing with ordinary overload resolution. Trace the two type-checking paths shown by the reveal_type results and add regression coverage for the intended consistent behavior.
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
- 42/100