Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Address review
  • Loading branch information
AlexWaygood committed Sep 25, 2024
commit 64777662e7cabb058dac805247f27002e5d0667e
2 changes: 1 addition & 1 deletion Doc/c-api/exceptions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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:`~class.__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*
Expand Down
10 changes: 5 additions & 5 deletions Doc/c-api/object.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 :attr:`cls.__mro__ <class.__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)
Expand All @@ -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:`~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).


Expand Down
16 changes: 7 additions & 9 deletions Doc/c-api/type.rst
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ 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 (:attr:`cls.__dict__ <class.__dict__>`).
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.
Expand Down Expand Up @@ -141,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.

Expand Down Expand Up @@ -176,31 +176,29 @@ Type Objects
.. c:function:: PyObject* PyType_GetName(PyTypeObject *type)

Return the type's name. Equivalent to getting the type's
:attr:`~class.__name__` attribute.
: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 :attr:`~class.__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
:attr:`type.__qualname__ <class.__qualname__>` if
:attr:`type.__module__ <class.__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
:attr:`type.__module__ <class.__module__>` attribute.
:attr:`type.__module__` attribute.

.. versionadded:: 3.13

Expand Down
10 changes: 5 additions & 5 deletions Doc/c-api/typeobj.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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:`~class.__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:`~class.__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:`~class.__name__` attribute, and the :attr:`~class.__module__` attribute is undefined
:attr:`~type.__name__` attribute, and the :attr:`~class.__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.
Expand Down Expand Up @@ -1335,7 +1335,7 @@ 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:`~class.__doc__` attribute on the
type object. This is exposed as the :attr:`~type.__doc__` attribute on the
type and instances of the type.

**Inheritance:**
Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion Doc/extending/newtypes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ An interesting advantage of using the :c:member:`~PyTypeObject.tp_members` table
descriptors that are used at runtime is that any attribute defined this way can
have an associated doc string simply by providing the text in the table. An
application can use the introspection API to retrieve the descriptor from the
class object, and get the doc string using its :attr:`~class.__doc__` attribute.
class object, and get the doc string using its :attr:`~type.__doc__` attribute.

As with the :c:member:`~PyTypeObject.tp_methods` table, a sentinel entry with a :c:member:`~PyMethodDef.ml_name` value
of ``NULL`` is required.
Expand Down
2 changes: 1 addition & 1 deletion Doc/extending/newtypes_tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ only used for variable-sized objects and should otherwise be zero.
If you want your type to be subclassable from Python, and your type has the same
:c:member:`~PyTypeObject.tp_basicsize` as its base type, you may have problems with multiple
inheritance. A Python subclass of your type will have to list your type first
in its :attr:`~class.__bases__`, or else it will not be able to call your type's
in its :attr:`~type.__bases__`, or else it will not be able to call your type's
:meth:`~object.__new__` method without getting an error. You can avoid this problem by
ensuring that your type has a larger value for :c:member:`~PyTypeObject.tp_basicsize` than its
base type does. Most of the time, this will be true anyway, because either your
Expand Down
6 changes: 3 additions & 3 deletions Doc/howto/annotations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ Your code will have to have a separate code path if the object
you're examining is a class (``isinstance(o, type)``).
In that case, best practice relies on an implementation detail
of Python 3.9 and before: if a class has annotations defined,
they are stored in the class's :attr:`~class.__dict__` dictionary. Since
they are stored in the class's :attr:`~type.__dict__` dictionary. Since
the class may or may not have annotations defined, best practice
is to call the :meth:`~dict.get` method on the class dict.

Expand All @@ -126,7 +126,7 @@ the type of ``ann`` using :func:`isinstance` before further
examination.

Note that some exotic or malformed type objects may not have
a :attr:`~class.__dict__` attribute, so for extra safety you may also wish
a :attr:`~type.__dict__` attribute, so for extra safety you may also wish
to use :func:`getattr` to access :attr:`!__dict__`.


Expand Down Expand Up @@ -247,5 +247,5 @@ on the class, you may observe unexpected behavior; see
quirks by using :func:`annotationlib.get_annotations` on Python 3.14+ or
:func:`inspect.get_annotations` on Python 3.10+. On earlier versions of
Python, you can avoid these bugs by accessing the annotations from the
class's :attr:`~class.__dict__`
class's :attr:`~type.__dict__`
(e.g., ``cls.__dict__.get('__annotations__', None)``).
2 changes: 1 addition & 1 deletion Doc/howto/enum.rst
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ The solution is to specify the module name explicitly as follows::
the source, pickling will be disabled.

The new pickle protocol 4 also, in some circumstances, relies on
:attr:`~class.__qualname__` being set to the location where pickle will be able
:attr:`~type.__qualname__` being set to the location where pickle will be able
to find the class. For example, if the class was made available in class
SomeData in the global scope::

Expand Down
4 changes: 2 additions & 2 deletions Doc/library/abc.rst
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ a helper class :class:`ABC` to alternatively define ABCs through inheritance:
that you can customize the behavior of :func:`issubclass` further without the
need to call :meth:`register` on every class you want to consider a
subclass of the ABC. (This class method is called from the
:meth:`~class.__subclasscheck__` method of the ABC.)
:meth:`~type.__subclasscheck__` method of the ABC.)

This method should return ``True``, ``False`` or :data:`NotImplemented`. If
it returns ``True``, the *subclass* is considered a subclass of this ABC.
Expand Down Expand Up @@ -149,7 +149,7 @@ a helper class :class:`ABC` to alternatively define ABCs through inheritance:
The :meth:`__subclasshook__` class method defined here says that any class
that has an :meth:`~iterator.__iter__` method in its
:attr:`~object.__dict__` (or in that of one of its base classes, accessed
via the :attr:`~class.__mro__` list) is considered a ``MyIterable`` too.
via the :attr:`~type.__mro__` list) is considered a ``MyIterable`` too.

Finally, the last line makes ``Foo`` a virtual subclass of ``MyIterable``,
even though it does not define an :meth:`~iterator.__iter__` method (it uses
Expand Down
2 changes: 1 addition & 1 deletion Doc/library/collections.rst
Original file line number Diff line number Diff line change
Expand Up @@ -874,7 +874,7 @@ they add the ability to access fields by name instead of position index.
``(1, 2)``, then ``x`` will be a required argument, ``y`` will default to
``1``, and ``z`` will default to ``2``.

If *module* is defined, the :attr:`~class.__module__` attribute of the
If *module* is defined, the :attr:`~type.__module__` attribute of the
named tuple is set to that value.

Named tuple instances do not have per-instance dictionaries, so they are
Expand Down
6 changes: 3 additions & 3 deletions Doc/library/email.contentmanager.rst
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@
* the type itself (``typ``)
* the type's fully qualified name (``typ.__module__ + '.' +
typ.__qualname__``).
* the type's :attr:`qualname <class.__qualname__>` (``typ.__qualname__``)
* the type's :attr:`name <class.__name__>` (``typ.__name__``).
* the type's :attr:`qualname <type.__qualname__>` (``typ.__qualname__``)
* the type's :attr:`name <type.__name__>` (``typ.__name__``).

If none of the above match, repeat all of the checks above for each of
the types in the :term:`MRO` (:attr:`typ.__mro__ <class.__mro__>`).
the types in the :term:`MRO` (:attr:`typ.__mro__ <type.__mro__>`).
Finally, if no other key
yields a handler, check for a handler for the key ``None``. If there is
no handler for ``None``, raise a :exc:`KeyError` for the fully
Expand Down
2 changes: 1 addition & 1 deletion Doc/library/email.headerregistry.rst
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ variant, :attr:`~.BaseHeader.max_count` is set to 1.
class. When *use_default_map* is ``True`` (the default), the standard
mapping of header names to classes is copied in to the registry during
initialization. *base_class* is always the last class in the generated
class's :class:`~class.__bases__` list.
class's :class:`~type.__bases__` list.

The default mappings are:

Expand Down
18 changes: 10 additions & 8 deletions Doc/library/functions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1965,11 +1965,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 @@ -2055,20 +2055,22 @@ are always available. They are listed here in alphabetical order.

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:`~class.__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:`~class.__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 @@ -2078,7 +2080,7 @@ 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()
Expand Down
2 changes: 1 addition & 1 deletion Doc/library/pickle.rst
Original file line number Diff line number Diff line change
Expand Up @@ -953,7 +953,7 @@ a given class::
unpickled_class = pickle.loads(f.getvalue())

assert isinstance(unpickled_class, type)
assert unpickled_class.__name__ == "MyClass"
assert unpickled_type.__name__ == "MyClass"
assert unpickled_class.my_attribute == 1


Expand Down
4 changes: 2 additions & 2 deletions Doc/library/types.rst
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ Dynamic Type Creation
For classes that have an ``__orig_bases__`` attribute, this
function returns the value of ``cls.__orig_bases__``.
For classes without the ``__orig_bases__`` attribute,
:attr:`cls.__bases__ <class.__bases__>` is returned.
:attr:`cls.__bases__ <type.__bases__>` is returned.

Examples::

Expand Down Expand Up @@ -392,7 +392,7 @@ Standard names are defined for the following types:

In addition, when a class is defined with a :attr:`~object.__slots__` attribute, then for
each slot, an instance of :class:`!MemberDescriptorType` will be added as an attribute
on the class. This allows the slot to appear in the class's :attr:`~class.__dict__`.
on the class. This allows the slot to appear in the class's :attr:`~type.__dict__`.

.. impl-detail::

Expand Down
2 changes: 1 addition & 1 deletion Doc/library/typing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3252,7 +3252,7 @@ Introspection helpers
empty dictionary is returned.
* If *obj* is a class ``C``, the function returns a dictionary that merges
annotations from ``C``'s base classes with those on ``C`` directly. This
is done by traversing :attr:`C.__mro__ <class.__mro__>` and iteratively
is done by traversing :attr:`C.__mro__ <type.__mro__>` and iteratively
combining
``__annotations__`` dictionaries. Annotations on classes appearing
earlier in the :term:`method resolution order` always take precedence over
Expand Down
6 changes: 3 additions & 3 deletions Doc/reference/compound_stmts.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1416,7 +1416,7 @@ dictionary. The class name is bound to this class object in the original local
namespace.

The order in which attributes are defined in the class body is preserved
in the new class's :attr:`~class.__dict__`. Note that this is reliable only right
in the new class's :attr:`~type.__dict__`. Note that this is reliable only right
after the class is created and only for classes that were defined using
the definition syntax.

Expand Down Expand Up @@ -1448,7 +1448,7 @@ A list of :ref:`type parameters <type-params>` may be given in square brackets
immediately after the class's name.
This indicates to static type checkers that the class is generic. At runtime,
the type parameters can be retrieved from the class's
:attr:`~class.__type_params__` attribute. See :ref:`generic-classes` for more.
:attr:`~type.__type_params__` attribute. See :ref:`generic-classes` for more.

.. versionchanged:: 3.12
Type parameter lists are new in Python 3.12.
Expand Down Expand Up @@ -1924,5 +1924,5 @@ all annotations are instead stored as strings::
therefore the function's :term:`docstring`.

.. [#] A string literal appearing as the first statement in the class body is
transformed into the namespace's :attr:`~class.__doc__` item and therefore
transformed into the namespace's :attr:`~type.__doc__` item and therefore
the class's :term:`docstring`.
Loading