Skip to content

Fix: allow instantiating type[None] and type(None)#21397

Open
tjhub1983 wants to merge 3 commits intopython:masterfrom
tjhub1983:master
Open

Fix: allow instantiating type[None] and type(None)#21397
tjhub1983 wants to merge 3 commits intopython:masterfrom
tjhub1983:master

Conversation

@tjhub1983
Copy link
Copy Markdown

Summary

Python 3 allows calling NoneType() and type(None)():

>>> NoneType()
None
>>> type(None)()
None

But mypy raised an Unsupported type type "NoneType" error when analyzing these callees.

Fix

In analyze_type_type_callee() (mypy/checkexpr.py), added an isinstance(item, NoneType) branch that returns a zero-argument CallableType returning NoneType. This allows both NoneType() and type(None)() to type-check correctly.

Fixes #19660.

tjhub1983 and others added 3 commits May 2, 2026 17:51
Python 3 allows calling NoneType() and type(None)():
    >>> NoneType()
    None
    >>> type(None)()
    None

But mypy raised an "unsupported_type_type" error in analyze_type_type_callee
when encountering a Type[None] callee. Fixed by adding isinstance(item, NoneType)
branch that returns a zero-argument CallableType returning NoneType.

Fixes python#19660.
`output` in Options defaults to None (meaning unset). The config parser
skips options when getattr(template, key, None) returns None, so
`output = json` in mypy.ini was silently ignored.

Fixed by adding `"output": str` to both ini_config_types and
toml_config_types, so the option is recognized and properly set.

Fixes python#21376.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cannot instantiate type "Type[None]"

1 participant