(🐞) `type.__call__` not checked properly
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
class A:
def __init__(self, x: int):
print(x)
A.__call__("a") # no error
A("a") # Argument 1 to "A" has incompatible type "str"; expected "int" [arg-type]
The typing spec says:
At runtime, a call to a class’ constructor typically results in the invocation of three methods in the following order:
- The
__call__method of the metaclass (which is typically supplied by thetypeclass but can be overridden by a custom metaclass and which is responsible for calling the next two methods)
So mypy is checking that usages of the call syntax (()) are conforming to the constructor type, but the functionally identical call attribute __call__. This is against the spec, which specifies that type checkers should mirror the behavior that __call__ will invoke __new__ and __init__
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 esaminando come mypy gestisce le chiamate al costruttore e le chiamate tramite attributo a type.__call__, usando l’esempio nell’issue come riproduzione. Segui come viene verificato A("a") rispetto a A.__call__("a"), quindi aggiungi una copertura che dimostri che entrambe le forme impongono il tipo dell’argomento del costruttore.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- devtools
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100