◐ Shell
clean mode source ↗

[3.12] gh-101100: Add a table of class attributes to the "Custom classes" section of the data model docs (#124480) by AlexWaygood · Pull Request #124558 · python/cpython

Expand Up @@ -283,9 +283,11 @@ are always available. They are listed here in alphabetical order. :func:`property`.
.. versionchanged:: 3.10 Class methods now inherit the method attributes (``__module__``, ``__name__``, ``__qualname__``, ``__doc__`` and ``__annotations__``) and have a new ``__wrapped__`` attribute. Class methods now inherit the method attributes (:attr:`~function.__module__`, :attr:`~function.__name__`, :attr:`~function.__qualname__`, :attr:`~function.__doc__` and :attr:`~function.__annotations__`) and have a new ``__wrapped__`` attribute.
.. versionchanged:: 3.11 Class methods can no longer wrap other :term:`descriptors <descriptor>` such as Expand Down Expand Up @@ -1217,8 +1219,9 @@ are always available. They are listed here in alphabetical order.
.. note::
:class:`object` does *not* have a :attr:`~object.__dict__`, so you can't assign arbitrary attributes to an instance of the :class:`object` class. :class:`object` instances do *not* have :attr:`~object.__dict__` attributes, so you can't assign arbitrary attributes to an instance of :class:`object`.

.. function:: oct(x) Expand Down Expand Up @@ -1831,10 +1834,11 @@ are always available. They are listed here in alphabetical order. For more information on static methods, see :ref:`types`.
.. versionchanged:: 3.10 Static methods now inherit the method attributes (``__module__``, ``__name__``, ``__qualname__``, ``__doc__`` and ``__annotations__``), have a new ``__wrapped__`` attribute, and are now callable as regular functions. Static methods now inherit the method attributes (:attr:`~function.__module__`, :attr:`~function.__name__`, :attr:`~function.__qualname__`, :attr:`~function.__doc__` and :attr:`~function.__annotations__`), have a new ``__wrapped__`` attribute, and are now callable as regular functions.

.. index:: Expand Down Expand Up @@ -1881,11 +1885,11 @@ are always available. They are listed here in alphabetical order. to be searched. The search starts from the class right after the *type*.
For example, if :attr:`~class.__mro__` of *object_or_type* is For example, if :attr:`~type.__mro__` of *object_or_type* is ``D -> B -> C -> A -> object`` and the value of *type* is ``B``, then :func:`super` searches ``C -> A -> object``.
The :attr:`~class.__mro__` attribute of the class corresponding to The :attr:`~type.__mro__` attribute of the class corresponding to *object_or_type* lists the method resolution search order used by both :func:`getattr` and :func:`super`. The attribute is dynamic and can change whenever the inheritance hierarchy is updated. Expand Down Expand Up @@ -1957,28 +1961,30 @@ are always available. They are listed here in alphabetical order.
With one argument, return the type of an *object*. The return value is a type object and generally the same object as returned by :attr:`object.__class__ <instance.__class__>`. :attr:`object.__class__`.
The :func:`isinstance` built-in function is recommended for testing the type of an object, because it takes subclasses into account.

With three arguments, return a new type object. This is essentially a dynamic form of the :keyword:`class` statement. The *name* string is the class name and becomes the :attr:`~definition.__name__` attribute. the class name and becomes the :attr:`~type.__name__` attribute. The *bases* tuple contains the base classes and becomes the :attr:`~class.__bases__` attribute; if empty, :class:`object`, the :attr:`~type.__bases__` attribute; if empty, :class:`object`, the ultimate base of all classes, is added. The *dict* dictionary contains attribute and method definitions for the class body; it may be copied or wrapped before becoming the :attr:`~object.__dict__` attribute. The following two statements create identical :class:`type` objects: or wrapped before becoming the :attr:`~type.__dict__` attribute. The following two statements create identical :class:`!type` objects:
>>> class X: ... a = 1 ... >>> X = type('X', (), dict(a=1))
See also :ref:`bltin-type-objects`. See also:
* :ref:`Documentation on attributes and methods on classes <class-attrs-and-methods>`. * :ref:`bltin-type-objects`
Keyword arguments provided to the three argument form are passed to the appropriate metaclass machinery (usually :meth:`~object.__init_subclass__`) Expand All @@ -1988,18 +1994,18 @@ are always available. They are listed here in alphabetical order. See also :ref:`class-customization`.
.. versionchanged:: 3.6 Subclasses of :class:`type` which don't override ``type.__new__`` may no Subclasses of :class:`!type` which don't override ``type.__new__`` may no longer use the one-argument form to get the type of an object.
.. function:: vars() vars(object)
Return the :attr:`~object.__dict__` attribute for a module, class, instance, or any other object with a :attr:`~object.__dict__` attribute. or any other object with a :attr:`!__dict__` attribute.
Objects such as modules and instances have an updateable :attr:`~object.__dict__` attribute; however, other objects may have write restrictions on their :attr:`~object.__dict__` attributes (for example, classes use a :attr:`!__dict__` attributes (for example, classes use a :class:`types.MappingProxyType` to prevent direct dictionary updates).
Without an argument, :func:`vars` acts like :func:`locals`. Note, the Expand Down