Bug report (Regression): bad overload resolution in `--strict` mode
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 20.6k
- Forks
- 3.3k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
Bug Report
The following code type-checked with mypy 1.16.1 in --strict mode but does not type-check with mypy 1.17 and the master branch (currently eb07c060c) in --strict mode. Bisecting points to the commit 33d1eedc0.
Note that the problem does not occur if --strict mode is disabled.
To Reproduce
import inspect
import typing
from typing import Any, ClassVar
def is_classvar(cls: type, scope: dict[Any, type]) -> bool:
ann = inspect.get_annotations(cls, eval_str=True, locals=scope).get("kind")
if ann is None:
raise Exception("Should be annotated.")
return typing.get_origin(ann) is not ClassVar
Actual Behavior
mypy --strict test_any.py
test_any.py:9: error: Non-overlapping identity check (left operand type: "ParamSpec", right operand type: "<typing special form>") [comparison-overlap]
Found 1 error in 1 file (checked 1 source file)
Your Environment
- Mypy version used:
mypy 1.17andmaster(bad),mypy 1.16.1(good) - Mypy command-line flags:
--strict - Mypy configuration options from
mypy.ini(and other config files): - Python version used:
3.13
Note that reveal_type(ann) gives Any | None and that annotating ann: Any | None solves the problem.
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne mit dem Reproducer in test_any.py und dem durch Commit 33d1eedc0 eingeführten Verhalten. Führe mypy --strict für das Beispiel in den betroffenen und den zuvor funktionierenden Versionen aus; als erledigt gilt es, wenn das Beispiel unter --strict die Typprüfung besteht, ohne eine explizite ann: Any | None-Annotation zu erfordern.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- devtools
- Issue-Typ
- Bug
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Klar beschrieben
- Anfängerfreundlichkeit
- 52/100