File tree Expand file tree Collapse file tree 3 files changed +32
-32
lines changed
Expand file tree Collapse file tree 3 files changed +32
-32
lines changed Original file line number Diff line number Diff line change @@ -705,6 +705,17 @@ Decorators
705705 Inheriting from a deprecated class now also raises a runtime
706706 :py:exc: `DeprecationWarning `.
707707
708+ .. decorator :: disjoint_base
709+
710+ See :pep: `800 `. A class decorator that marks a class as a "disjoint base", meaning that
711+ child classes of the decorated class cannot inherit from other disjoint bases that are not
712+ parent classes of the decorated class.
713+
714+ This helps type checkers to detect unreachable code and to understand when two types
715+ can overlap.
716+
717+ .. versionadded :: 4.15.0
718+
708719.. decorator :: final
709720
710721 See :py:func: `typing.final ` and :pep: `591 `. In ``typing `` since 3.8.
@@ -748,17 +759,6 @@ Decorators
748759 improved, and ``typing_extensions `` backports these performance
749760 improvements.
750761
751- .. decorator :: solid_base
752-
753- See :pep: `800 `. A class decorator that marks a class as a "solid base", meaning that
754- child classes of the decorated class cannot inherit from other solid bases that are not
755- parent classes of the decorated class.
756-
757- This helps type checkers to detect unreachable code and to understand when two types
758- can overlap.
759-
760- .. versionadded :: 4.15.0
761-
762762Functions
763763~~~~~~~~~
764764
Original file line number Diff line number Diff line change 8484 clear_overloads ,
8585 dataclass_transform ,
8686 deprecated ,
87+ disjoint_base ,
8788 evaluate_forward_ref ,
8889 final ,
8990 get_annotations ,
101102 reveal_type ,
102103 runtime ,
103104 runtime_checkable ,
104- solid_base ,
105105 type_repr ,
106106)
107107
@@ -6671,16 +6671,16 @@ def cached(self): ...
66716671 self .assertIs (True , Methods .cached .__final__ )
66726672
66736673
6674- class SolidBaseTests (BaseTestCase ):
6675- def test_solid_base_unmodified (self ):
6674+ class DisjointBaseTests (BaseTestCase ):
6675+ def test_disjoint_base_unmodified (self ):
66766676 class C : ...
6677- self .assertIs (C , solid_base (C ))
6677+ self .assertIs (C , disjoint_base (C ))
66786678
6679- def test_dunder_solid_base (self ):
6680- @solid_base
6679+ def test_dunder_disjoint_base (self ):
6680+ @disjoint_base
66816681 class C : ...
66826682
6683- self .assertIs (C .__solid_base__ , True )
6683+ self .assertIs (C .__disjoint_base__ , True )
66846684
66856685
66866686class RevealTypeTests (BaseTestCase ):
Original file line number Diff line number Diff line change 7171 'clear_overloads' ,
7272 'dataclass_transform' ,
7373 'deprecated' ,
74+ 'disjoint_base' ,
7475 'Doc' ,
7576 'evaluate_forward_ref' ,
7677 'get_overloads' ,
9495 'reveal_type' ,
9596 'runtime' ,
9697 'runtime_checkable' ,
97- 'solid_base' ,
9898 'Text' ,
9999 'TypeAlias' ,
100100 'TypeAliasType' ,
@@ -322,30 +322,30 @@ class Other(Leaf): # Error reported by type checker
322322 return f
323323
324324
325- if hasattr (typing , "solid_base " ): # 3.15
326- solid_base = typing .solid_base
325+ if hasattr (typing , "disjoint_base " ): # 3.15
326+ disjoint_base = typing .disjoint_base
327327else :
328- def solid_base (cls ):
329- """This decorator marks a class a solid base.
328+ def disjoint_base (cls ):
329+ """This decorator marks a class as a disjoint base.
330330
331- Child classes of a solid base cannot inherit from other solid bases that are
332- not parent classes of the solid base.
331+ Child classes of a disjoint base cannot inherit from other disjoint bases that are
332+ not parent classes of the disjoint base.
333333
334334 For example:
335335
336- @solid_base
337- class Solid1 : pass
336+ @disjoint_base
337+ class Disjoint1 : pass
338338
339- @solid_base
340- class Solid2 : pass
339+ @disjoint_base
340+ class Disjoint2 : pass
341341
342- class Solid3(Solid1, Solid2 ): pass # Type checker error
342+ class Disjoint3(Disjoint1, Disjoint2 ): pass # Type checker error
343343
344- Type checkers can use knowledge of solid bases to detect unreachable code
344+ Type checkers can use knowledge of disjoint bases to detect unreachable code
345345 and determine when two types can overlap.
346346
347347 See PEP 800."""
348- cls .__solid_base__ = True
348+ cls .__disjoint_base__ = True
349349 return cls
350350
351351
You can’t perform that action at this time.
0 commit comments