Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions mypy/checkexpr.py
Original file line number Diff line number Diff line change
Expand Up @@ -1926,6 +1926,17 @@ def analyze_type_type_callee(self, item: ProperType, context: Context) -> Type:
return self.analyze_type_type_callee(tuple_fallback(item), context)
if isinstance(item, TypedDictType):
return self.typeddict_callable_from_context(item)
if isinstance(item, NoneType):
# NoneType() returns None, so treat it as a callable that returns None
return CallableType(
arg_types=[],
arg_kinds=[],
arg_names=[],
ret_type=NoneType(),
fallback=self.named_type("builtins.function"),
name=None,
from_type_type=True,
)

self.msg.unsupported_type_type(item, context)
return AnyType(TypeOfAny.from_error)
Expand Down
12 changes: 12 additions & 0 deletions test-data/unit/check-classes.test
Original file line number Diff line number Diff line change
Expand Up @@ -3866,6 +3866,18 @@ def f(a: Type[Tuple[int, int]]):
a() # E: Cannot instantiate type "type[tuple[int, int]]"
[builtins fixtures/tuple.pyi]

[case testTypeUsingTypeCNoneType]
NoneType = type(None)
type(None)()
NoneType()
def f(n: type[None]):
n()
def g(n: type[NoneType]):
n()
f(NoneType)
g(NoneType)
[out]

[case testTypeUsingTypeCNamedTuple]
from typing import Type, NamedTuple
N = NamedTuple('N', [('x', int), ('y', int)])
Expand Down
Loading