Skip to content
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

gh-96397: Document that attributes need not be identifiers #96454

Merged
merged 2 commits into from
Sep 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
11 changes: 9 additions & 2 deletions Doc/glossary.rst
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,17 @@ Glossary
:exc:`StopAsyncIteration` exception. Introduced by :pep:`492`.

attribute
A value associated with an object which is referenced by name using
dotted expressions. For example, if an object *o* has an attribute
A value associated with an object which is usually referenced by name
using dotted expressions.
For example, if an object *o* has an attribute
*a* it would be referenced as *o.a*.

It is possible to give an object an attribute whose name is not an
identifier as defined by :ref:`identifiers`, for example using
:func:`setattr`, if the object allows it.
Such an attribute will not be accessible using a dotted expression,
and would instead need to be retrieved with :func:`getattr`.

awaitable
An object that can be used in an :keyword:`await` expression. Can be
a :term:`coroutine` or an object with an :meth:`__await__` method.
Expand Down
8 changes: 8 additions & 0 deletions Doc/library/functions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,7 @@ are always available. They are listed here in alphabetical order.
string. The string must be the name of one of the object's attributes. The
function deletes the named attribute, provided the object allows it. For
example, ``delattr(x, 'foobar')`` is equivalent to ``del x.foobar``.
*name* need not be a Python identifier (see :func:`setattr`).
jeff5 marked this conversation as resolved.
Show resolved Hide resolved


.. _func-dict:
Expand Down Expand Up @@ -738,6 +739,7 @@ are always available. They are listed here in alphabetical order.
value of that attribute. For example, ``getattr(x, 'foobar')`` is equivalent to
``x.foobar``. If the named attribute does not exist, *default* is returned if
provided, otherwise :exc:`AttributeError` is raised.
*name* need not be a Python identifier (see :func:`setattr`).
jeff5 marked this conversation as resolved.
Show resolved Hide resolved

.. note::

Expand Down Expand Up @@ -1575,6 +1577,12 @@ are always available. They are listed here in alphabetical order.
object allows it. For example, ``setattr(x, 'foobar', 123)`` is equivalent to
``x.foobar = 123``.

*name* need not be a Python identifier as defined in :ref:`identifiers`
jeff5 marked this conversation as resolved.
Show resolved Hide resolved
unless the object chooses to enforce that, for example in a custom
:meth:`~object.__getattribute__` or via :attr:`~object.__slots__`.
An attribute whose name is not an identifier will not be accessible using
the dot notation, but is accessible through :func:`getattr` etc..

.. note::

Since :ref:`private name mangling <private-name-mangling>` happens at
Expand Down