Mypy signals error with Protocol and __rpow__ method with three arguments
Offen
Dieses Issue hat noch niemand übernommen.
bug
good-first-issue
topic-protocols
- Vorherrschende Sprache
- Python
- Sterne
- 20.6k
- Forks
- 3.3k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
Okay, this is a head-scratcher. 😕
To Reproduce
# test_case.py
from typing import Protocol, overload, runtime_checkable
@runtime_checkable
class PowableProto(Protocol):
@overload
def __pow__(self, other: "PowableProto") -> "PowableProto":
...
@overload
def __pow__(self, other: "PowableProto", modulo: "PowableProto") -> "PowableProto": # <- fine
...
@overload
def __rpow__(self, other: "PowableProto") -> "PowableProto":
...
@overload
def __rpow__(self, other: "PowableProto", modulo: "PowableProto") -> "PowableProto": # <- this (of all things) breaks
...
@overload
def __rpOw__(self, other: "PowableProto") -> "PowableProto":
...
@overload
def __rpOw__(self, other: "PowableProto", modulo: "PowableProto") -> "PowableProto": # <- fine
...
% mypy --version
mypy 0.910
% mypy --config-file=/dev/null test_case.py
/dev/null: No [mypy] section in config file
test_case.py:15: error: Invalid signature "def (test_case.PowableProto, test_case.PowableProto, test_case.PowableProto) -> test_case.PowableProto"
Found 1 error in 1 file (checked 1 source file)
Expected vs. Actual Behavior
I would expect at least consistent behavior among the overridden methods. This only crops up with __rpow__ for some reason. (I have tested many others.)
Your Environment
- Mypy version used: 0.910
- Mypy command-line flags:
--config-file=/dev/null(i.e., force default configuration) - Mypy configuration options from
mypy.ini(and other config files): N/A - Python version used:
Python 3.9.6(frompython --version) - Operating system and version:
Darwin Kernel Version 19.6.0: Thu May 6 00:48:39 PDT 2021; root:xnu-6153.141.33~1/RELEASE_X86_64(fromuname -v)
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
Führe zunächst den bereitgestellten mypy-Befehl für test_case.py aus und vergleiche, wie die Drei-Argument-Überladungen von pow und rpow behandelt werden. Verfolge die Signaturvalidierung, die den Fehler erzeugt, stelle dann ein konsistentes Verhalten her und überprüfe, dass der Reproducer keine ungültige Signatur mehr meldet.
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
- Ruhig
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 55/100