Skip to content
Merged
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
5 changes: 5 additions & 0 deletions mypy/subtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1091,6 +1091,11 @@ def visit_type_type(self, left: TypeType) -> bool:
right = self.right
if isinstance(right, TypeType):
return self._is_subtype(left.item, right.item)
if isinstance(right, Overloaded) and right.is_type_obj():
# Same as in other direction: if it's a constructor callable, all
# items should belong to the same class' constructor, so it's enough
# to check one of them.
return self._is_subtype(left, right.items[0])
if isinstance(right, CallableType):
if self.proper_subtype and not right.is_type_obj():
# We can't accept `Type[X]` as a *proper* subtype of Callable[P, X]
Expand Down
16 changes: 16 additions & 0 deletions test-data/unit/check-assert-type-fail.test
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,19 @@ def f(si: arr.array[int]):
from typing import assert_type, Callable
def myfunc(arg: int) -> None: pass
assert_type(myfunc, Callable[[int], None]) # E: Expression is of type "Callable[[Arg(int, 'arg')], None]", not "Callable[[int], None]"

[case testAssertTypeOverload]
from typing import assert_type, overload

class Foo:
@overload
def __new__(cls, x: int) -> Foo: ...
@overload
def __new__(cls, x: str) -> Foo: ...
def __new__(cls, x: "int | str") -> Foo:
return cls(0)

assert_type(Foo, type[Foo])
A = Foo
assert_type(A, type[Foo])
[builtins fixtures/tuple.pyi]