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(
16681668 # An Enum() call that failed SemanticAnalyzerPass2.check_enum_call().
16691669 return callee .ret_type , callee
16701670
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 :
16771672 self .chk .fail (
16781673 message_registry .CANNOT_INSTANTIATE_PROTOCOL .format (callee .type_object ().name ),
16791674 context ,
Original file line number Diff line number Diff line change @@ -1603,7 +1603,7 @@ class C:
16031603 pass
16041604
16051605def f(cls: Type[P]) -> P:
1606- return cls() # OK
1606+ return cls() # E: Cannot instantiate protocol class "P"
16071607def g() -> P:
16081608 return P() # E: Cannot instantiate protocol class "P"
16091609
@@ -1625,7 +1625,7 @@ class C:
16251625 pass
16261626
16271627def f(cls: Type[P]) -> P:
1628- return cls() # OK
1628+ return cls() # E: Cannot instantiate protocol class "P"
16291629
16301630Alias = P
16311631GoodAlias = C
@@ -1646,14 +1646,14 @@ class C:
16461646 pass
16471647
16481648var: Type[P]
1649- var()
1649+ var() # E: Cannot instantiate protocol class "P"
16501650if int():
16511651 var = P # E: Can only assign concrete classes to a variable of type "Type[P]"
16521652 var = B # OK
16531653 var = C # OK
16541654
16551655var_old = None # type: Type[P] # Old syntax for variable annotations
1656- var_old()
1656+ var_old() # E: Cannot instantiate protocol class "P"
16571657if int():
16581658 var_old = P # E: Can only assign concrete classes to a variable of type "Type[P]"
16591659 var_old = B # OK
@@ -1669,7 +1669,7 @@ class Logger:
16691669class C(Protocol):
16701670 @classmethod
16711671 def action(cls) -> None:
1672- cls() #OK for classmethods
1672+ cls() # E: Cannot instantiate protocol class "C"
16731673 Logger.log(cls) #OK for classmethods
16741674[builtins fixtures/classmethod.pyi]
16751675
Original file line number Diff line number Diff line change @@ -1023,7 +1023,7 @@ T = TypeVar('T', bound=HasX)
10231023class Meta(type):
10241024 def do_x(cls: Type[T]) -> T:
10251025 cls.x
1026- return cls()
1026+ return cls() # E: Cannot instantiate protocol class "HasX"
10271027
10281028class Good(metaclass=Meta):
10291029 x: int
You can’t perform that action at this time.
0 commit comments