File tree Expand file tree Collapse file tree 3 files changed +7
-12
lines changed Expand file tree Collapse file tree 3 files changed +7
-12
lines changed Original file line number Diff line number Diff line change @@ -1668,12 +1668,7 @@ def check_callable_call(
1668
1668
# An Enum() call that failed SemanticAnalyzerPass2.check_enum_call().
1669
1669
return callee .ret_type , callee
1670
1670
1671
- if (
1672
- callee .is_type_obj ()
1673
- and callee .type_object ().is_protocol
1674
- # Exception for Type[...]
1675
- and not callee .from_type_type
1676
- ):
1671
+ if callee .is_type_obj () and callee .type_object ().is_protocol :
1677
1672
self .chk .fail (
1678
1673
message_registry .CANNOT_INSTANTIATE_PROTOCOL .format (callee .type_object ().name ),
1679
1674
context ,
Original file line number Diff line number Diff line change @@ -1603,7 +1603,7 @@ class C:
1603
1603
pass
1604
1604
1605
1605
def f(cls: Type[P]) -> P:
1606
- return cls() # OK
1606
+ return cls() # E: Cannot instantiate protocol class "P"
1607
1607
def g() -> P:
1608
1608
return P() # E: Cannot instantiate protocol class "P"
1609
1609
@@ -1625,7 +1625,7 @@ class C:
1625
1625
pass
1626
1626
1627
1627
def f(cls: Type[P]) -> P:
1628
- return cls() # OK
1628
+ return cls() # E: Cannot instantiate protocol class "P"
1629
1629
1630
1630
Alias = P
1631
1631
GoodAlias = C
@@ -1646,14 +1646,14 @@ class C:
1646
1646
pass
1647
1647
1648
1648
var: Type[P]
1649
- var()
1649
+ var() # E: Cannot instantiate protocol class "P"
1650
1650
if int():
1651
1651
var = P # E: Can only assign concrete classes to a variable of type "Type[P]"
1652
1652
var = B # OK
1653
1653
var = C # OK
1654
1654
1655
1655
var_old = None # type: Type[P] # Old syntax for variable annotations
1656
- var_old()
1656
+ var_old() # E: Cannot instantiate protocol class "P"
1657
1657
if int():
1658
1658
var_old = P # E: Can only assign concrete classes to a variable of type "Type[P]"
1659
1659
var_old = B # OK
@@ -1669,7 +1669,7 @@ class Logger:
1669
1669
class C(Protocol):
1670
1670
@classmethod
1671
1671
def action(cls) -> None:
1672
- cls() #OK for classmethods
1672
+ cls() # E: Cannot instantiate protocol class "C"
1673
1673
Logger.log(cls) #OK for classmethods
1674
1674
[builtins fixtures/classmethod.pyi]
1675
1675
Original file line number Diff line number Diff line change @@ -1023,7 +1023,7 @@ T = TypeVar('T', bound=HasX)
1023
1023
class Meta(type):
1024
1024
def do_x(cls: Type[T]) -> T:
1025
1025
cls.x
1026
- return cls()
1026
+ return cls() # E: Cannot instantiate protocol class "HasX"
1027
1027
1028
1028
class Good(metaclass=Meta):
1029
1029
x: int
You can’t perform that action at this time.
0 commit comments