-
-
Notifications
You must be signed in to change notification settings - Fork 34.4k
gh-148639: Implement PEP 800 (typing.disjoint_base) #148640
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
3f7202c
27d989a
0cd8736
adb6834
90b4418
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -126,6 +126,7 @@ | |
| 'cast', | ||
| 'clear_overloads', | ||
| 'dataclass_transform', | ||
| 'disjoint_base', | ||
| 'evaluate_forward_ref', | ||
| 'final', | ||
| 'get_args', | ||
|
|
@@ -2794,6 +2795,29 @@ class Other(Leaf): # Error reported by type checker | |
| return f | ||
|
|
||
|
|
||
| def disjoint_base(cls): | ||
| """This decorator marks a class as a disjoint base. | ||
|
|
||
| Child classes of a disjoint base cannot inherit from other disjoint bases that are | ||
| not parent classes of the disjoint base. | ||
|
|
||
| For example: | ||
|
|
||
| @disjoint_base | ||
| class Disjoint1: pass | ||
|
|
||
| @disjoint_base | ||
| class Disjoint2: pass | ||
|
|
||
| class Disjoint3(Disjoint1, Disjoint2): pass # Type checker error | ||
|
|
||
| Type checkers can use knowledge of disjoint bases to detect unreachable code | ||
| and determine when two types can overlap. | ||
| """ | ||
| cls.__disjoint_base__ = True | ||
| return cls | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should it
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, we added that to final for backward compatibility since previous versions of the decorator didn't do it. Newer decorators that have had this assignment since the beginning (such as |
||
|
|
||
|
|
||
| # Some unconstrained type variables. These were initially used by the container types. | ||
| # They were never meant for export and are now unused, but we keep them around to | ||
| # avoid breaking compatibility with users who import them. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| Implement :pep:`800`, adding the :deco:`typing.disjoint_base` decorator. | ||
| Patch by Jelle Zijlstra. |
Uh oh!
There was an error while loading. Please reload this page.