Overload resolution collapses to Any when Any is nested inside a generic argument, not just top-level
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 55/100
Direzione di ricerca
Inizia eseguendo lo snippet fornito con mypy 2.3.0 e leggendo la sezione della documentazione “Type checking calls to overloads”. Traccia la risoluzione degli overload per Sequence[Any] rispetto a Sequence[int]; il lavoro è completato quando il comportamento previsto è stabilito e il tipo rivelato, l’implementazione o la documentazione corrisponde a tale decisione.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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
- Lingua principale
- Python
- Stelle
- 20.6k
- Fork
- 3.3k
- Merge medio
- 1g 12h
- PR unite (30g)
- 58
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di python/mypy
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
-
documentation
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
-
bug topic-configuration topic-error-reporting
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
-
bug topic-attrs
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
anthropics/skills#1811 · 1 commento ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
speaches-ai/speaches#678 ·
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
datalayer/mcp-compose#42 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
conda-forge/spacy-feedstock#177 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
UKGovernmentBEIS/inspect_evals#2523 ·