Default value of keyword parameter in custom Protocol is not used
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 20.6k
- Forks
- 3.3k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
Bug Report
Consider the code below:
from typing import Protocol
class P(Protocol):
def foo(self, n: int = 666) -> None: ...
class F:
def foo(self, n: int = 666) -> None: ...
class S:
def foo(self, n: int = 999) -> None: ...
def bar(x: P) -> None: ...
bar(F())
bar(S())
Expected Behavior
Warning in the last code line about incompatibility of class S and protocol P, because the default value of parameter n in P.foo is not ellipsis and the numerical value of n in S.foo is different.
Actual Behavior
Mypy does not generate any warnings.
Your Environment
- Mypy version used:
8.12
0.820+dev.8642b351cff94c471333256f9cd6867807384f01
- Mypy command-line flags:
none
- Mypy configuration options from
mypy.ini(and other config files):
[mypy]
pretty = True
show_error_codes = True
strict = True
disallow_any_unimported = True
disallow_any_expr = True
disallow_any_decorated = True
disallow_any_explicit = True
no_warn_no_return = True
warn_unreachable = True
- Python version used:
3.8.10 (64-bit), 3.9.5 (64-bit), 3.10 beta (64-bit)
- Operating system and version:
Windows 10 64-bit
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 damit, mypy auf dem Reproducer im Issue auszuführen, und verfolge die Prüfung der Protokollkompatibilität für den Standardwert des Parameters n von foo. Als erledigt gilt, wenn mypy die Inkompatibilität zwischen S und P meldet und F weiterhin als kompatibel akzeptiert.
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
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100