Fix: allow instantiating type[None] and type(None)#21397
Open
tjhub1983 wants to merge 3 commits intopython:masterfrom
Open
Fix: allow instantiating type[None] and type(None)#21397tjhub1983 wants to merge 3 commits intopython:masterfrom
tjhub1983 wants to merge 3 commits intopython:masterfrom
Conversation
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.
for more information, see https://pre-commit.ci
`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.
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
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Python 3 allows calling
NoneType()andtype(None)():But mypy raised an
Unsupported type type "NoneType"error when analyzing these callees.Fix
In
analyze_type_type_callee()(mypy/checkexpr.py), added anisinstance(item, NoneType)branch that returns a zero-argumentCallableTypereturningNoneType. This allows bothNoneType()andtype(None)()to type-check correctly.Fixes #19660.