Bug Report
The docs state the return type becomes Any only when "an argument [is] of type Any". But when the Any is nested inside a generic type argument (Sequence[Any] vs Sequence[int]), mypy also collapses the result to Any, even though the first overload matches unambiguously. Is this intended? If so, the "Type checking calls to overloads" section should probably document the nested case.
To Reproduce
from collections.abc import Sequence
from typing import Any, overload, reveal_type
@overload
def f(s: Sequence[int]) -> str: ...
@overload
def f(s: object) -> int: ...
def f(s: object) -> int | str:
return "2"
concrete: Sequence[int] = [1]
nested_any: Sequence[Any] = [1]
reveal_type(f(concrete)) # Revealed type is "str" (expected)
reveal_type(f(nested_any)) # Revealed type is "Any" (surprising)
Expected Behavior
reveal_type on Sequence[Any] should show "str"
Actual Behavior
reveal_type on Sequence[Any] shows "Any"
Your Environment
- Mypy version used: mypy 2.3.0
- Mypy command-line flags: none
- Mypy configuration options from
mypy.ini (and other config files): none
- Python version used: Python 3.14.6
Bug Report
The docs state the return type becomes Any only when "an argument [is] of type Any". But when the Any is nested inside a generic type argument (Sequence[Any] vs Sequence[int]), mypy also collapses the result to Any, even though the first overload matches unambiguously. Is this intended? If so, the "Type checking calls to overloads" section should probably document the nested case.
To Reproduce
Expected Behavior
reveal_type on Sequence[Any] should show "str"
Actual Behavior
reveal_type on Sequence[Any] shows "Any"
Your Environment
mypy.ini(and other config files): none