Skip to content

Commit 8352d04

Browse files
PEP 800: Note Python 3.12 behavior change, note reference impl (python#4555)
1 parent e04b07d commit 8352d04

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

peps/pep-0800.rst

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,18 @@ use CPython's behavior to determine when to use the ``@disjoint_base`` decorator
190190
add support for alternative implementations (for example, branching on the value of :py:data:`sys.implementation.name <sys.implementation>`),
191191
stubs could condition the presence of the ``@disjoint_base`` decorator on the implementation where necessary.
192192

193-
Similarly, the exact set of classes that are disjoint bases at runtime may change in future versions of Python.
193+
Although the concept of "disjoint bases" (referred to as "solid bases") in the CPython implementation has existed
194+
for decades, the rules for deciding which classes are disjoint bases have occasionally changed.
195+
Before Python 3.12, adding a ``__dict__`` or support for weakrefs relative to the base class could make a
196+
class a disjoint base. In practice, this often meant that Python-implemented classes inheriting from
197+
classes implemented in C, such as :func:`~collections.namedtuple` classes, were themselves disjoint bases.
198+
This behavior was changed in Python 3.12 by
199+
`python/cpython#96028 <https://github.com/python/cpython/pull/96028>`__.
200+
This PEP focuses on supporting the behavior of Python 3.12 and later, which is simpler and easier to understand.
201+
Type checkers may choose to implement a version of the pre-3.12 behavior if they wish, but doing this correctly
202+
requires information that is not currently available in the type system.
203+
204+
The exact set of classes that are disjoint bases at runtime may change again in future versions of Python.
194205
If this were to happen, the type stubs used by type checkers could be updated to reflect this new reality.
195206
In other words, this PEP adds the concept of disjoint bases to the type system, but it does not prescribe exactly
196207
which classes are disjoint bases.
@@ -360,7 +371,10 @@ explain to users why type checkers treat certain branches as unreachable.
360371
Reference Implementation
361372
========================
362373

363-
None yet.
374+
The runtime implementation of the ``@disjoint_base`` decorator will be available in
375+
typing-extensions 4.15.0.
376+
`python/mypy#19678 <https://github.com/python/mypy/pull/19678>`__
377+
implements support for disjoint bases in mypy and in the stubtest tool.
364378

365379
Appendix
366380
========

0 commit comments

Comments
 (0)