Disallow type(x) if x has a protocol type
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 20.6k
- Forks
- 3.3k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
Modules can implement protocols, so type(x) is not necessarily a type object if x has a protocol type.
from typing import Protocol
class P(Protocol):
def f(self) -> None: ...
def f(p: P) -> None:
reveal_type(type(p)) # type[P] (incorrect!)
It's probably best to to generate an error if type is called on an object with a protocol type, as suggested by @hauntsaninja in https://github.com/python/mypy/issues/16890#issuecomment-1937529825.
See #16890 for more context.
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
Beginnen Sie mit dem Aufruf type(p) im Protocol-Beispiel und lesen Sie #16890 für den angegebenen Kontext. Verifizieren Sie, dass protokolltypisierte Werte nicht mehr das falsche Ergebnis type[P] erzeugen und dass der beabsichtigte Fehler durch die relevanten Tests abgedeckt ist.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- tooling
- Issue-Typ
- Bug
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 45/100