Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
18 changes: 18 additions & 0 deletions test-data/unit/check-classes.test
Original file line number Diff line number Diff line change
Expand Up @@ -3866,6 +3866,24 @@ def f(a: Type[Tuple[int, int]]):
a() # E: Cannot instantiate type "type[tuple[int, int]]"
[builtins fixtures/tuple.pyi]

[case testTypeUsingTypeCNoneType]
from typing_extensions import assert_type

[builtins fixtures/tuple.pyi]

NoneType = type(None)
assert_type(type(None)(), None)
assert_type(NoneType(), None)

def f(n: type[None]):
assert_type(n(), None)
def g(n: type[NoneType]): # type: ignore[valid-type]
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please use standard test syntax: remove the [out] at the bottom and replace this with a # E: whatever the error was. You can see some more examples around this.

assert_type(n(), None)

f(NoneType)
g(NoneType)
[out]

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