Fails to flag `None` passed to constructor of `enum.Enum`-based classes
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 fails to flag None passed to constructor of enum.Enum-based classes.
To Reproduce
import enum
class Foo(enum.Enum):
one = 1
Foo(None)
Note that changing to class Foo(int, enum.Enum) does make mypy flag the error. However, the two aren't equivalent as the latter lets you do Foo.one + 1 while the former requires Foo.one.value + 1.
Edit: In fact, in both forms it fails to flag invalid arguments such as Foo(2). I do realize this is a slightly different case, which is why I'm focusing on None which has different behavior between the two.
Expected Behavior
I would expect mypy to flag the last line as an error:
error: No overload variant of "Foo" matches argument type "None" [call-overload]
Actual Behavior
Mypy reports no errors.
Your Environment
Tested on
- Mypy 1.13.0 and 1.15.0
- CPython 3.11.10
Used mypy --strict file.py and just mypy file.py.
Contents of mypy.ini (I actually use a pyproject.toml file, but have tested with only this ini-file):
[mypy]
check_untyped_defs = true
disallow_any_generics = false
disallow_incomplete_defs = false
disallow_subclassing_any = false
disallow_untyped_calls = false
disallow_untyped_decorators = true
disallow_untyped_defs = false
enable_error_code = truthy-bool, truthy-iterable
extra_checks = true
ignore_missing_imports = false
local_partial_types = true
no_implicit_optional = true
no_implicit_reexport = false
no_namespace_packages = true
python_version = 3.11
strict_equality = true
warn_redundant_casts = true
warn_return_any = false
warn_unused_configs = true
warn_unused_ignores = true
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 con il riproduttore enum.Enum fornito e confrontalo con il caso int, enum.Enum che segnala già un errore. Traccia il modo in cui mypy controlla le chiamate al costruttore per le classi basate su enum, quindi aggiungi la copertura per Foo(None) e per valori non validi come Foo(2); il lavoro è completo quando viene segnalato l’errore call-overload previsto.
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
- Abbastanza chiara
- Idoneità per principianti
- 38/100