FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Fix: allow instantiating type[None] and type(None) by tjhub1983 · Pull Request #21397 · python/mypy · GitHub

Repository navigation

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

Closed
tjhub1983 wants to merge 3 commits into
python:masterfrom
tjhub1983:master
Closed

tjhub1983 wants to merge 3 commits into
python:masterfrom
tjhub1983:master

Conversation

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.

tjhub1983 left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

This PR fixes issue #21376, adding to the config types list allowing it to be set in mypy.ini / mypy.toml. The change is minimal and follows the existing pattern. Could I get a review?

Copy link
Copy Markdown
Author

Hi maintainers! This PR allows instantiating type[None] and type(None), which were previously rejected by mypy. Happy to make any adjustments if you have feedback.

A5rocks commented May 7, 2026

Copy link
Copy Markdown
Collaborator

Closed in favor of #19782

A5rocks closed this May 7, 2026

A5rocks commented May 7, 2026

Copy link
Copy Markdown
Collaborator

Oh sorry, I didn't notice the output config option was in this PR too.. hmm. If it works, please submit a new PR. It's a different approach than #21416 so presumably one of the approaches is worse :-)

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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]"

2 participants


Back | FazBrowse Home | New Git URL