From b92de51c2f94ed0f9fe55b6aba86cba51737ad20 Mon Sep 17 00:00:00 2001 From: tjhub1983 <2368494411@qq.com> Date: Sat, 2 May 2026 17:51:52 +0800 Subject: [PATCH 1/3] Fix: allow instantiating type[None] and type(None) 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/mypy#19660. --- mypy/checkexpr.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/mypy/checkexpr.py b/mypy/checkexpr.py index c9296bd5e875d..7aff11b8810ff 100644 --- a/mypy/checkexpr.py +++ b/mypy/checkexpr.py @@ -1934,6 +1934,15 @@ def analyze_type_type_callee(self, item: ProperType, context: Context) -> Type: # We support Type of namedtuples but not of tuples in general if isinstance(item, TupleType) and tuple_fallback(item).type.fullname != "builtins.tuple": return self.analyze_type_type_callee(tuple_fallback(item), context) + if isinstance(item, NoneType): + # type(None)() and NoneType() are valid in Python 3 + return CallableType( + arg_types=[], + arg_kinds=[], + arg_names=[], + ret_type=item, + fallback=None, + ) if isinstance(item, TypedDictType): return self.typeddict_callable_from_context(item) From 8cd10ea21ab2b2a5ab33801fd3a996ba5fe646a2 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 2 May 2026 10:09:14 +0000 Subject: [PATCH 2/3] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- mypy/checkexpr.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/mypy/checkexpr.py b/mypy/checkexpr.py index 7aff11b8810ff..7b4214b090c0d 100644 --- a/mypy/checkexpr.py +++ b/mypy/checkexpr.py @@ -1937,11 +1937,7 @@ def analyze_type_type_callee(self, item: ProperType, context: Context) -> Type: if isinstance(item, NoneType): # type(None)() and NoneType() are valid in Python 3 return CallableType( - arg_types=[], - arg_kinds=[], - arg_names=[], - ret_type=item, - fallback=None, + arg_types=[], arg_kinds=[], arg_names=[], ret_type=item, fallback=None ) if isinstance(item, TypedDictType): return self.typeddict_callable_from_context(item) From c062d615cb0b6d0ca85035afcf36c3f3539b3a5d Mon Sep 17 00:00:00 2001 From: tjhub1983 <2368494411@qq.com> Date: Sat, 2 May 2026 21:14:19 +0800 Subject: [PATCH 3/3] Fix: allow setting `output` in mypy.ini / mypy.toml `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/mypy#21376. --- mypy/config_parser.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mypy/config_parser.py b/mypy/config_parser.py index 97fa01b8dd215..5fe976fc77161 100644 --- a/mypy/config_parser.py +++ b/mypy/config_parser.py @@ -207,6 +207,7 @@ def split_commas(value: str) -> list[str]: "exclude": lambda s: [s.strip()], "packages": try_split, "modules": try_split, + "output": str, } # Reuse the ini_config_types and overwrite the diff @@ -229,6 +230,7 @@ def split_commas(value: str) -> list[str]: "exclude": str_or_array_as_list, "packages": try_split, "modules": try_split, + "output": str, } )