-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Implement PEP 800 (@disjoint_base) #19678
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
Conversation
https://peps.python.org/pep-0800/ - Recognize the @disjoint_base decorator - Error if a class definition has incompatible disjoint bases - Recognize that classes with incompatible disjoint bases cannot exist - Check in stubtest that @disjoint_base is correctly applied
@@ -1484,13 +1484,7 @@ def analyze_decorator_or_funcbase_access( | |||
if isinstance(defn, Decorator): | |||
return analyze_var(name, defn.var, itype, mx) | |||
typ = function_type(defn, mx.chk.named_type("builtins.function")) | |||
is_trivial_self = False | |||
if isinstance(defn, Decorator): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This condition can never match because we already check for Decorator a few lines up.
for more information, see https://pre-commit.ci
This comment has been minimized.
This comment has been minimized.
Primer analysis:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for implementing the feature! Looks good, just a few ideas about additional things to test.
|
||
class C1: pass | ||
class C2(Disjoint1, C1): pass | ||
class C3(DisjointChild, Disjoint1): pass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some ideas for additional test cases:
- Test reversed order of bases.
- Test with all three
Disjoint*
bases. - Test a subclass of
C3
/C2
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, also added some more tests.
Diff from mypy_primer, showing the effect of this PR on open source code: mypy (https://github.com/python/mypy)
+ mypy/checkmember.py:1488: error: Subclass of "FuncBase" and "Decorator" cannot exist: have distinct disjoint bases [unreachable]
+ mypy/checkmember.py:1488: note: See https://mypy.rtfd.io/en/stable/_refs.html#code-unreachable for more info
+ mypy/checkmember.py:1490: error: Statement is unreachable [unreachable]
steam.py (https://github.com/Gobot1234/steam.py)
- steam/chat.py:161: error: Unused "type: ignore" comment [unused-ignore]
|
https://peps.python.org/pep-0800/
__slots__
.