`typing.Protocol` is explicitly treated as not a `type`
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 20.6k
- Forks
- 3.3k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
Bug Report
At runtime, isinstance(typing.Protocol, type) is True. When type checking, mypy appears to special-case Protocol:
- mypy:
<typing special form> - Pylance/Pyright:
(class) Protocol
To Reproduce
from typing import Protocol
class A(Protocol): pass
assert Protocol in A.__bases__
bases: tuple[type, ...] = (Protocol, *A.__bases__)
Expected Behavior
Same as Pyright, Protocol is a class (type), no errors.
Actual Behavior
main.py:5: error: Non-overlapping container check (element type: "<typing special form>", container item type: "type") [comparison-overlap]
main.py:6: error: Argument 1 to <tuple> has incompatible type "<typing special form>"; expected "type" [arg-type]
Your Environment
- Mypy version used: 1.0.0, 1.10.1, 1.20.2, 2.3.1
- Mypy command-line flags:
--strict - Python version used: 3.6 - 3.14
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 der bereitgestellten Python-Reproduktion unter mypy --strict und vergleiche deren Diagnosen mit dem angegebenen Verhalten von Pyright. Finde die spezielle Behandlung von typing.Protocol in mypy und füge Tests hinzu oder aktualisiere die Testabdeckung, sodass Protocol als Typ akzeptiert wird und die Reproduktion keine Fehler erzeugt.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- devtools
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Aktiv
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 52/100