Cannot instantiate type "Type[None]"
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
Mypy claims Cannot instantiate type "Type[None]" when you try to do so. However, you actually can do this in python, and perhaps have been able to do this ever since python 3...
This affects both types.NoneType and type(None). Also, function signatures that get at those.
To Reproduce
https://mypy-play.net/?mypy=master&python=3.12&gist=26b0ab20fc6d45de0edff4f8a374b0a7
from types import NoneType
type(None)()
NoneType()
def f(n: type[None]):
n()
def g(n: type[NoneType]):
n()
f(NoneType)
g(NoneType)
Actual Behavior
main.py:2: error: Cannot instantiate type "type[None]" [misc]
main.py:3: error: Cannot instantiate type "type[None]" [misc]
main.py:5: error: Cannot instantiate type "type[None]" [misc]
main.py:6: error: NoneType should not be used as a type, please use None instead [valid-type]
main.py:7: error: Cannot instantiate type "type[None]" [misc]
Found 5 errors in 1 file (checked 1 source file)
Expected Behavior
Running this python file doesn't result in any runtime problems, so I would expect no errors. (Except perhaps main.py:6: error: NoneType should not be used as a type, please use None instead [valid-type], which seems like more of a style suggstion, and so might still be valid.)
Possibly related, perhaps even fixable by this issue: https://github.com/python/mypy/issues/19308
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 la riproduzione collegata di mypy-play da main.py e traccia dove vengono prodotti i cinque diagnostici. Il lavoro è completato quando i casi validi di istanziazione di NoneType e type(None) non producono più errori errati, mentre il diagnostico accettabile sull’uso del tipo NoneType può rimanere.
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à
- Tranquilla
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 52/100