Incorrect note references builtins.pyi instead of the class definition
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 20.6k
- Fork
- 3.3k
- Metriche di merge delle PR
- Metriche PR in attesa
Descrizione
Bug Report
When reporting a "Unexpected keyword argument" error for an initializer, the note can incorrectly reference builtins.pyi instead of the class definition.
To Reproduce
https://mypy-play.net/?gist=b50a11afee5d039fb382667dee8b529f
class Foo:
bar: str
def f() -> Foo:
foo = Foo(bar="bar")
return foo
f()
For context, I was using pydantic, but forgot to make the class in question inherit from pydantic.BaseModel. But this isn't specific to pydantic.
Expected Behavior
The note should include the class definition, not an incorrect link to builtins.pyi.
This was misleading because I thought my class was shadowing a built-in one, so I tried renaming it.
Actual Behavior
main.py:5: error: Unexpected keyword argument "bar" for "Foo" [call-arg]
/layers/google.python.pip/pip/lib/python3.12/site-packages/mypy/typeshed/stdlib/builtins.pyi:117: note: "Foo" defined here
I believe the line referenced here is for object.__init__().
Your Environment
- Mypy version used: 1.19.1
- Mypy command-line flags: n/a
- Mypy configuration options from
mypy.ini(and other config files): n/a (default for mypy playground) - Python version used: python3.12
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia eseguendo il riproduttore Python dell’issue e confronta la nota diagnostica dell’inizializzatore con il riferimento previsto alla definizione della classe. Traccia il modo in cui l’errore identifica l’inizializzatore e formatta la sua posizione nel codice sorgente, quindi verifica che il fix segnali ancora correttamente l’argomento con parola chiave imprevisto senza puntare a builtins.pyi.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- compilers
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 45/100