Classmethod bound with an additional name trigger stubtest errors
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 20.6k
- Forks
- 3.3k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
Bug Report
Classmethods bound with an additional name trigger stubtest errors.
To Reproduce
Consider the following trivial module and companion typing stub file
# mod.py
class T:
def a(self): pass
b = a
@classmethod
def c(cls): pass
d = c
# mod.pyi
class T:
def a(self) -> None: pass
b = a
@classmethod
def c(cls) -> None: pass
d = c
then run stubtest the following way:
PYTHONPATH=$PWD stubtest mod
Expected Behavior
stubtest succeeds with no output printed
Actual Behavior
error: mod.T.d variable differs from runtime type def () -> Any
Stub: in file /home/dalcinl/tmp/pkg/mod.pyi:6
def (cls: Type[mod.T])
Runtime: in file /tmp/mod.py:4
<bound method T.c of <class 'mod.T'>>
Found 1 error (checked 1 module)
Please note that the issue comes from a @classmethod, a regular method does not trigger the error.
Your Environment
- Mypy version used: 1.4.1
- Mypy command-line flags: none
- Mypy configuration options from
mypy.ini(and other config files): none - Python version used: 3.11.4
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
Reproduziere den Bericht mit den zusammengehörigen Beispielen mod.py und mod.pyi und führe PYTHONPATH=$PWD stubtest mod aus. Vergleiche, wie stubtest mit T.c und dem Alias T.d umgeht, und überprüfe dann die Änderung anhand dieser Reproduktion; abgeschlossen ist die Änderung, wenn der Befehl ohne Ausgabe oder Fehler erfolgreich ausgeführt wird.
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
- 50/100