python / python/mypy

Classmethod bound with an additional name trigger stubtest errors

Aperta
#15,717 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

bug topic-stubtest
Lingua principale
Python
Stelle
20.6k
Fork
3.3k
Metriche di merge delle PR
Metriche PR in attesa

Descrizione

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

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Riproduci il problema riportato con gli esempi abbinati mod.py e mod.pyi ed esegui PYTHONPATH=$PWD stubtest mod. Confronta il modo in cui stubtest gestisce T.c e l'alias T.d, quindi verifica la modifica con questa riproduzione; la modifica è completata quando il comando viene eseguito correttamente senza output né errori.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
python
Ambito
devtools
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Specificata chiaramente
Idoneità per principianti
50/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.