10000 gh-101100: Add a table of class attributes to the "Custom classes" section of the data model docs by AlexWaygood · Pull Request #124480 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-101100: Add a table of class attributes to the "Custom classes" section of the data model docs #124480

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Sep 25, 2024
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
Fixes
  • Loading branch information
AlexWaygood committed Sep 25, 2024
commit fbfe927e0411d594406afb7402bb433f2b966841
2 changes: 1 addition & 1 deletion Doc/c-api/object.rst
8000
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ Object Protocol
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
Expand Down
2 changes: 1 addition & 1 deletion Doc/glossary.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1241,7 +1241,7 @@ Glossary
type
The type of a Python object determines what kind of object it is; every
object has a type. An object's type is accessible as its
:attr:`~instance.__class__` attribute or can be retrieved with
:attr:`~object.__class__` attribute or can be retrieved with
``type(obj)``.

type alias
Expand Down
2 changes: 1 addition & 1 deletion Doc/library/functions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2048,7 +2048,7 @@ 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.
Expand Down
8 changes: 4 additions & 4 deletions Doc/library/functools.rst
Original file line number Diff line number Diff line change
Expand Up @@ -742,10 +742,10 @@ have three read-only attributes:
The keyword arguments that will be supplied when the :class:`partial` object is
called.

:class:`partial` objects are like :class:`function` objects in that they are
callable, weak referenceable, and can have attributes. There are some important
differences. For instance, the :attr:`~function.__name__` and
:attr:`function.__doc__` attributes
:class:`partial` objects are like :ref:`function objects <user-defined-funcs>`
in that they are callable, weak referenceable, and can have attributes.
There are some important differences. For instance, the
:attr:`~function.__name__` and :attr:`function.__doc__` attributes
are not created automatically. Also, :class:`partial` objects defined in
classes behave like static methods and do not transform into bound methods
during instance attribute look-up.
2 changes: 1 addition & 1 deletion Doc/library/unittest.mock.rst
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ the *new_callable* argument to :func:`patch`.
Accessing any attribute not in this list will raise an :exc:`AttributeError`.

If *spec* is an object (rather than a list of strings) then
:attr:`~instance.__class__` returns the class of the spec object. This
:attr:`~object.__class__` returns the class of the spec object. This
allows mocks to pass :func:`isinstance` tests.

* *spec_set*: A stricter variant of *spec*. If used, attempting to *set*
Expand Down
4 changes: 2 additions & 2 deletions Doc/reference/datamodel.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1106,7 +1106,7 @@ have the following two methods available:
.. doctest::

>>> int.__subclasses__()
[<class 'bool'>, <enum 'IntEnum'>, <flag 'IntFlag'>, <class 're._constants._NamedIntConstant'>]
[<class 'bool'>, <enum 'IntEnum'>, <flag 'IntFlag'>, <class 're._constants._NamedIntConstant'>, <class 're._ZeroSentinel'>]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This failed spuriously on https://github.com/python/cpython/actions/runs/11043320393/job/30677452220?pr=124569. I suspect it depends on whether GC has run and collected the MyIntEnum class. Example:

>>> print(int.__subclasses__())
[<class 'bool'>, <enum 'IntEnum'>, <flag 'IntFlag'>, <class 're._constants._NamedIntConstant'>, <class 're._ZeroSentinel'>]
>>> import enum
>>> def f():
...     class MyIntEnum(int, enum.Enum): pass
...     
>>> f()
>>> print(int.__subclasses__())
[<class 'bool'>, <enum 'IntEnum'>, <flag 'IntFlag'>, <class 're._constants._NamedIntConstant'>, <class 're._ZeroSentinel'>, <enum 'MyIntEnum'>]
>>> import gc
>>> gc.collect()
31
>>> print(int.__subclasses__())
[<class 'bool'>, <enum 'IntEnum'>, <flag 'IntFlag'>, <class 're._constants._NamedIntConstant'>, <class 're._ZeroSentinel'>]
>>> 

I'll send a PR to change this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, interesting! Thanks!


Class instances
---------------
Expand Down Expand Up @@ -2412,7 +2412,7 @@ Notes on using *__slots__*:
to provide per-attribute docstrings that will be recognised by
:func:`inspect.getdoc` and displayed in the output of :func:`help`.

* :attr:`~instance.__class__` assignment works only if both classes have the
* :attr:`~object.__class__` assignment works only if both classes have the
same *__slots__*.

* :ref:`Multiple inheritance <tut-multiple>` with multiple slotted parent
Expand Down
2 changes: 1 addition & 1 deletion Doc/whatsnew/2.3.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1116,7 +1116,7 @@ Here are all of the changes that Python 2.3 makes to the core Python language.
removed: you can now assign to the :attr:`~class.__name__` and :attr:`~class.__bases__`
attributes of new-style classes. There are some restrictions on what can be
assigned to :attr:`!__bases__` along the lines of those relating to assigning to
an instance's :attr:`~instance.__class__` attribute.
an instance's :attr:`~object.__class__` attribute.

.. ======================================================================

Expand Down
Loading
0