From 6a0c2c7556e2904091dffd6b30b77cffb4c1240f Mon Sep 17 00:00:00 2001 From: Thejesh <35212698+thejesh23@users.noreply.github.com> Date: Sun, 1 Nov 2026 16:26:53 -0800 Subject: [PATCH 1/3] gh-161007: Add a glossary entry for "virtual subclass" --- Doc/glossary.rst | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/Doc/glossary.rst b/Doc/glossary.rst index a31bd53f06294db..f01450ced734de6 100644 --- a/Doc/glossary.rst +++ b/Doc/glossary.rst @@ -29,9 +29,10 @@ Glossary Abstract base classes complement :term:`duck-typing` by providing a way to define interfaces when other techniques like :func:`hasattr` would be clumsy or subtly wrong (for example with - :ref:`magic methods `). ABCs introduce virtual - subclasses, which are classes that don't inherit from a class but are - still recognized by :func:`isinstance` and :func:`issubclass`; see the + :ref:`magic methods `). ABCs introduce + :term:`virtual subclasses `, which are classes that + don't inherit from a class but are still recognized by + :func:`isinstance` and :func:`issubclass`; see the :mod:`abc` module documentation. Python comes with many built-in ABCs for data structures (in the :mod:`collections.abc` module), numbers (in the :mod:`numbers` module), streams (in the :mod:`io` module), import finders @@ -1727,6 +1728,15 @@ Glossary A computer defined entirely in software. Python's virtual machine executes the :term:`bytecode` emitted by the bytecode compiler. + virtual subclass + A class that :func:`issubclass` and :func:`isinstance` treat as a + subclass of an :term:`abstract base class` even though it does not + inherit from it. A class becomes a virtual subclass when it is + registered with the ABC's :meth:`~abc.ABCMeta.register` method, or when + the ABC's :meth:`~abc.ABCMeta.__subclasshook__` recognizes it. The ABC + does not appear in the virtual subclass's :term:`MRO`, and none of the + ABC's methods are inherited. + walrus operator A light-hearted way to refer to the :ref:`assignment expression ` operator ``:=`` because it looks a bit like a From 9d7e124693f8b9bf3eda677a9808393e3acec4ed Mon Sep 17 00:00:00 2001 From: Thejesh <35212698+thejesh23@users.noreply.github.com> Date: Sun, 1 Nov 2026 16:28:36 -0800 Subject: [PATCH 2/3] Keep "virtual subclass" tied to ABCMeta.register(), as in the abc docs --- Doc/glossary.rst | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Doc/glossary.rst b/Doc/glossary.rst index f01450ced734de6..de1580615169bfc 100644 --- a/Doc/glossary.rst +++ b/Doc/glossary.rst @@ -1731,11 +1731,12 @@ Glossary virtual subclass A class that :func:`issubclass` and :func:`isinstance` treat as a subclass of an :term:`abstract base class` even though it does not - inherit from it. A class becomes a virtual subclass when it is - registered with the ABC's :meth:`~abc.ABCMeta.register` method, or when - the ABC's :meth:`~abc.ABCMeta.__subclasshook__` recognizes it. The ABC - does not appear in the virtual subclass's :term:`MRO`, and none of the - ABC's methods are inherited. + inherit from it. A class is made a virtual subclass by registering + it with the ABC's :meth:`~abc.ABCMeta.register` method. An ABC can + also recognize classes without registration by overriding + :meth:`~abc.ABCMeta.__subclasshook__`. The ABC does not appear in + the virtual subclass's :term:`MRO`, and none of the ABC's methods are + inherited. walrus operator A light-hearted way to refer to the :ref:`assignment expression From 12b73d817058c7c3c8ee31203b989dd1c09272d0 Mon Sep 17 00:00:00 2001 From: Thejesh <35212698+thejesh23@users.noreply.github.com> Date: Mon, 2 Nov 2026 17:05:06 -0800 Subject: [PATCH 3/3] Address review: drop the __subclasshook__ and MRO sentences --- Doc/glossary.rst | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/Doc/glossary.rst b/Doc/glossary.rst index de1580615169bfc..f0934dc2e138771 100644 --- a/Doc/glossary.rst +++ b/Doc/glossary.rst @@ -1732,11 +1732,7 @@ Glossary A class that :func:`issubclass` and :func:`isinstance` treat as a subclass of an :term:`abstract base class` even though it does not inherit from it. A class is made a virtual subclass by registering - it with the ABC's :meth:`~abc.ABCMeta.register` method. An ABC can - also recognize classes without registration by overriding - :meth:`~abc.ABCMeta.__subclasshook__`. The ABC does not appear in - the virtual subclass's :term:`MRO`, and none of the ABC's methods are - inherited. + it with the ABC's :meth:`~abc.ABCMeta.register` method. walrus operator A light-hearted way to refer to the :ref:`assignment expression