Skip to content

Commit 719f89e

Browse files
committed
Remove TypeType exception for abstract instantiation
If A is abstract, it's weird to me that we have a difference in the following two calls: ``` from abc import abstractmethod, ABCMeta class A(metaclass=ABCMeta): @AbstractMethod def __init__(self, a: int) -> None: pass def test_a(A_t: type[A]) -> None: A_t(1) A(1) ``` Mypy tries to then enforce soundness by preventing you from passing `A` to a parameter of `type[A]`. But this is very unpopular, since there are legitimate uses of `A` that have nothing to do with instantiation. See #4717 As mentioned in https://discuss.python.org/t/compatibility-of-protocol-class-object-with-type-t-and-type-any/48442/2 I think we should switch to disallowing instantiation of `type[Proto]` and `type[Abstract]`. This also makes tackling `__init__` unsoundness more tractable. If people want unsound `__init__`, they can use `Callable[..., P]`.
1 parent 1f200dd commit 719f89e

File tree

1 file changed

+0
-4
lines changed

1 file changed

+0
-4
lines changed

mypy/checkexpr.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1671,8 +1671,6 @@ def check_callable_call(
16711671
if (
16721672
callee.is_type_obj()
16731673
and callee.type_object().is_protocol
1674-
# Exception for Type[...]
1675-
and not callee.from_type_type
16761674
):
16771675
self.chk.fail(
16781676
message_registry.CANNOT_INSTANTIATE_PROTOCOL.format(callee.type_object().name),
@@ -1681,8 +1679,6 @@ def check_callable_call(
16811679
elif (
16821680
callee.is_type_obj()
16831681
and callee.type_object().is_abstract
1684-
# Exception for Type[...]
1685-
and not callee.from_type_type
16861682
and not callee.type_object().fallback_to_any
16871683
):
16881684
type = callee.type_object()

0 commit comments

Comments
 (0)