Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

JelleZijlstra
Copy link
Member

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
  • The self check found a line of dead code in mypy itself, due to classes that are disjoint bases from __slots__.

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):
Copy link
Member Author

@JelleZijlstra JelleZijlstra Aug 18, 2025

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.

This comment has been minimized.

@JelleZijlstra
Copy link
Member Author

Primer analysis:

  • the new hit in mypy is correct (and already fixed in this PR)
  • In steam.py mypy now correctly finds that a class (defined under if TYPE_CHECKING) cannot exist. Not sure why they already had a type ignore since pyright doesn't currently detect this either.

Copy link
Collaborator

@JukkaL JukkaL left a 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
Copy link
Collaborator

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.

Copy link
Member Author

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.

Copy link
Contributor

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]

@JukkaL JukkaL merged commit 0d23c61 into python:master Aug 19, 2025
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants