mirror of
https://github.com/python/cpython.git
synced 2025-11-09 01:51:26 +00:00
[3.13] gh-101100: Add a table of class attributes to the "Custom classes" section of the data model docs (#124480) (#124556)
This commit is contained in:
parent
068e734bb5
commit
9f2e6ca199
41 changed files with 250 additions and 208 deletions
|
|
@ -733,7 +733,7 @@ Exception Classes
|
|||
This creates a class object derived from :exc:`Exception` (accessible in C as
|
||||
:c:data:`PyExc_Exception`).
|
||||
|
||||
The :attr:`!__module__` attribute of the new class is set to the first part (up
|
||||
The :attr:`~type.__module__` attribute of the new class is set to the first part (up
|
||||
to the last dot) of the *name* argument, and the class name is set to the last
|
||||
part (after the last dot). The *base* argument can be used to specify alternate
|
||||
base classes; it can either be only one class or a tuple of classes. The *dict*
|
||||
|
|
|
|||
|
|
@ -367,14 +367,14 @@ Object Protocol
|
|||
The result will be ``1`` when at least one of the checks returns ``1``,
|
||||
otherwise it will be ``0``.
|
||||
|
||||
If *cls* has a :meth:`~class.__subclasscheck__` method, it will be called to
|
||||
If *cls* has a :meth:`~type.__subclasscheck__` method, it will be called to
|
||||
determine the subclass status as described in :pep:`3119`. Otherwise,
|
||||
*derived* is a subclass of *cls* if it is a direct or indirect subclass,
|
||||
i.e. contained in ``cls.__mro__``.
|
||||
i.e. contained in :attr:`cls.__mro__ <type.__mro__>`.
|
||||
|
||||
Normally only class objects, i.e. instances of :class:`type` or a derived
|
||||
class, are considered classes. However, objects can override this by having
|
||||
a :attr:`~class.__bases__` attribute (which must be a tuple of base classes).
|
||||
a :attr:`~type.__bases__` attribute (which must be a tuple of base classes).
|
||||
|
||||
|
||||
.. c:function:: int PyObject_IsInstance(PyObject *inst, PyObject *cls)
|
||||
|
|
@ -386,15 +386,15 @@ Object Protocol
|
|||
The result will be ``1`` when at least one of the checks returns ``1``,
|
||||
otherwise it will be ``0``.
|
||||
|
||||
If *cls* has a :meth:`~class.__instancecheck__` method, it will be called to
|
||||
If *cls* has a :meth:`~type.__instancecheck__` method, it will be called to
|
||||
determine the subclass status as described in :pep:`3119`. Otherwise, *inst*
|
||||
is an instance of *cls* if its class is a subclass of *cls*.
|
||||
|
||||
An instance *inst* can override what is considered its class by having a
|
||||
:attr:`~instance.__class__` attribute.
|
||||
:attr:`~object.__class__` attribute.
|
||||
|
||||
An object *cls* can override if it is considered a class, and what its base
|
||||
classes are, by having a :attr:`~class.__bases__` attribute (which must be a tuple
|
||||
classes are, by having a :attr:`~type.__bases__` attribute (which must be a tuple
|
||||
of base classes).
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -53,7 +53,8 @@ Type Objects
|
|||
.. c:function:: PyObject* PyType_GetDict(PyTypeObject* type)
|
||||
|
||||
Return the type object's internal namespace, which is otherwise only
|
||||
exposed via a read-only proxy (``cls.__dict__``). This is a
|
||||
exposed via a read-only proxy (:attr:`cls.__dict__ <type.__dict__>`).
|
||||
This is a
|
||||
replacement for accessing :c:member:`~PyTypeObject.tp_dict` directly.
|
||||
The returned dictionary must be treated as read-only.
|
||||
|
||||
|
|
@ -140,7 +141,7 @@ Type Objects
|
|||
Return true if *a* is a subtype of *b*.
|
||||
|
||||
This function only checks for actual subtypes, which means that
|
||||
:meth:`~class.__subclasscheck__` is not called on *b*. Call
|
||||
:meth:`~type.__subclasscheck__` is not called on *b*. Call
|
||||
:c:func:`PyObject_IsSubclass` to do the same check that :func:`issubclass`
|
||||
would do.
|
||||
|
||||
|
|
@ -174,29 +175,30 @@ Type Objects
|
|||
|
||||
.. c:function:: PyObject* PyType_GetName(PyTypeObject *type)
|
||||
|
||||
Return the type's name. Equivalent to getting the type's ``__name__`` attribute.
|
||||
Return the type's name. Equivalent to getting the type's
|
||||
:attr:`~type.__name__` attribute.
|
||||
|
||||
.. versionadded:: 3.11
|
||||
|
||||
.. c:function:: PyObject* PyType_GetQualName(PyTypeObject *type)
|
||||
|
||||
Return the type's qualified name. Equivalent to getting the
|
||||
type's ``__qualname__`` attribute.
|
||||
type's :attr:`~type.__qualname__` attribute.
|
||||
|
||||
.. versionadded:: 3.11
|
||||
|
||||
.. c:function:: PyObject* PyType_GetFullyQualifiedName(PyTypeObject *type)
|
||||
|
||||
Return the type's fully qualified name. Equivalent to
|
||||
``f"{type.__module__}.{type.__qualname__}"``, or ``type.__qualname__`` if
|
||||
``type.__module__`` is not a string or is equal to ``"builtins"``.
|
||||
``f"{type.__module__}.{type.__qualname__}"``, or :attr:`type.__qualname__`
|
||||
if :attr:`type.__module__` is not a string or is equal to ``"builtins"``.
|
||||
|
||||
.. versionadded:: 3.13
|
||||
|
||||
.. c:function:: PyObject* PyType_GetModuleName(PyTypeObject *type)
|
||||
|
||||
Return the type's module name. Equivalent to getting the ``type.__module__``
|
||||
attribute.
|
||||
Return the type's module name. Equivalent to getting the
|
||||
:attr:`type.__module__` attribute.
|
||||
|
||||
.. versionadded:: 3.13
|
||||
|
||||
|
|
|
|||
|
|
@ -567,12 +567,12 @@ and :c:data:`PyType_Type` effectively act as defaults.)
|
|||
|
||||
For :ref:`statically allocated type objects <static-types>`,
|
||||
the *tp_name* field should contain a dot.
|
||||
Everything before the last dot is made accessible as the :attr:`__module__`
|
||||
Everything before the last dot is made accessible as the :attr:`~type.__module__`
|
||||
attribute, and everything after the last dot is made accessible as the
|
||||
:attr:`~definition.__name__` attribute.
|
||||
:attr:`~type.__name__` attribute.
|
||||
|
||||
If no dot is present, the entire :c:member:`~PyTypeObject.tp_name` field is made accessible as the
|
||||
:attr:`~definition.__name__` attribute, and the :attr:`__module__` attribute is undefined
|
||||
:attr:`~type.__name__` attribute, and the :attr:`~type.__module__` attribute is undefined
|
||||
(unless explicitly set in the dictionary, as explained above). This means your
|
||||
type will be impossible to pickle. Additionally, it will not be listed in
|
||||
module documentations created with pydoc.
|
||||
|
|
@ -1131,7 +1131,7 @@ and :c:data:`PyType_Type` effectively act as defaults.)
|
|||
|
||||
.. c:macro:: Py_TPFLAGS_MANAGED_DICT
|
||||
|
||||
This bit indicates that instances of the class have a ``__dict__``
|
||||
This bit indicates that instances of the class have a `~object.__dict__`
|
||||
attribute, and that the space for the dictionary is managed by the VM.
|
||||
|
||||
If this flag is set, :c:macro:`Py_TPFLAGS_HAVE_GC` should also be set.
|
||||
|
|
@ -1335,8 +1335,8 @@ and :c:data:`PyType_Type` effectively act as defaults.)
|
|||
.. c:member:: const char* PyTypeObject.tp_doc
|
||||
|
||||
An optional pointer to a NUL-terminated C string giving the docstring for this
|
||||
type object. This is exposed as the :attr:`__doc__` attribute on the type and
|
||||
instances of the type.
|
||||
type object. This is exposed as the :attr:`~type.__doc__` attribute on the
|
||||
type and instances of the type.
|
||||
|
||||
**Inheritance:**
|
||||
|
||||
|
|
@ -2036,7 +2036,7 @@ and :c:data:`PyType_Type` effectively act as defaults.)
|
|||
A collection of subclasses. Internal use only. May be an invalid pointer.
|
||||
|
||||
To get a list of subclasses, call the Python method
|
||||
:py:meth:`~class.__subclasses__`.
|
||||
:py:meth:`~type.__subclasses__`.
|
||||
|
||||
.. versionchanged:: 3.12
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue