| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
analyze_type_type_callee() had no case for mypy's internal NoneType, so calling a value of type type[None] (e.g. via type(None)() or a type[None]/type[types.NoneType] annotated callee) incorrectly produced a "Cannot instantiate type" error, even though this is valid at runtime and returns None. Fixes python#19660
|
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Summary
analyze_type_type_callee() in checkexpr.py had no branch for mypy's internal NoneType. As a result, calling a callee of type type[None] incorrectly produced Cannot instantiate type "type[None]", even though this is valid at runtime (type(None)() and NoneType() both return None).
Repro from the issue:
Before this change, mypy reported 4 spurious Cannot instantiate type "type[None]" errors (plus the expected NoneType should not be used as a type note). After this change, only the expected note remains.
Fix: add a case in analyze_type_type_callee that, for NoneType items, returns a nullary CallableType with return type NoneType(), mirroring how type(None) behaves at runtime.
Test plan
Fixes #19660