File tree Expand file tree Collapse file tree 3 files changed +27
-1
lines changed
Expand file tree Collapse file tree 3 files changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -2259,7 +2259,12 @@ def analyze_class_decorator_common(
22592259 if refers_to_fullname (decorator , FINAL_DECORATOR_NAMES ):
22602260 info .is_final = True
22612261 elif refers_to_fullname (decorator , DISJOINT_BASE_DECORATOR_NAMES ):
2262- info .is_disjoint_base = True
2262+ if info .is_protocol :
2263+ self .fail ("@disjoint_base cannot be used with protocol class" , decorator )
2264+ elif info .typeddict_type is not None :
2265+ self .fail ("@disjoint_base cannot be used with TypedDict" , decorator )
2266+ else :
2267+ info .is_disjoint_base = True
22632268 elif refers_to_fullname (decorator , TYPE_CHECK_ONLY_NAMES ):
22642269 info .is_type_check_only = True
22652270 elif (deprecated := self .get_deprecated (decorator )) is not None :
Original file line number Diff line number Diff line change @@ -4746,3 +4746,13 @@ tmp/a.py:8: note: Expected:
47464746tmp/a.py:8: note: def f(self) -> PNested
47474747tmp/a.py:8: note: Got:
47484748tmp/a.py:8: note: def f(self) -> CNested
4749+
4750+ [case testProtocolCannotBeDisjointBase]
4751+ from typing import Protocol
4752+ from typing_extensions import disjoint_base
4753+
4754+ @disjoint_base # E: @disjoint_base cannot be used with protocol class
4755+ class A(Protocol):
4756+ pass
4757+
4758+ [builtins fixtures/tuple.pyi]
Original file line number Diff line number Diff line change @@ -2515,6 +2515,17 @@ class ForwardDeclared: pass
25152515[builtins fixtures/dict.pyi]
25162516[typing fixtures/typing-full.pyi]
25172517
2518+ [case testTypedDictCannotBeDisjointBase]
2519+ from typing import TypedDict
2520+ from typing_extensions import disjoint_base
2521+
2522+ @disjoint_base # E: @disjoint_base cannot be used with TypedDict
2523+ class A(TypedDict):
2524+ pass
2525+
2526+ [builtins fixtures/dict.pyi]
2527+ [typing fixtures/typing-typeddict.pyi]
2528+
25182529[case testTypedDictTypeNarrowingWithFinalKey]
25192530from typing import Final, Optional, TypedDict
25202531
You can’t perform that action at this time.
0 commit comments