gh-96397: Document that attributes need not be identifiers (GH-96454)

Co-authored-by: C.A.M. Gerlach <CAM.Gerlach@Gerlach.CAM>
(cherry picked from commit 9a11ed8e50)

Co-authored-by: Jeff Allen <ja.py@farowl.co.uk>
This commit is contained in:
Miss Islington (bot) 2022-09-29 16:25:10 -07:00 committed by Pablo Galindo
parent 815ad02586
commit f20ad5ef45
No known key found for this signature in database
GPG key ID: FFE87404168BD847
2 changed files with 17 additions and 2 deletions

View file

@ -136,10 +136,17 @@ Glossary
:exc:`StopAsyncIteration` exception. Introduced by :pep:`492`. :exc:`StopAsyncIteration` exception. Introduced by :pep:`492`.
attribute attribute
A value associated with an object which is referenced by name using A value associated with an object which is usually referenced by name
dotted expressions. For example, if an object *o* has an attribute using dotted expressions.
For example, if an object *o* has an attribute
*a* it would be referenced as *o.a*. *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 awaitable
An object that can be used in an :keyword:`await` expression. Can be An object that can be used in an :keyword:`await` expression. Can be
a :term:`coroutine` or an object with an :meth:`__await__` method. a :term:`coroutine` or an object with an :meth:`__await__` method.

View file

@ -403,6 +403,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 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 function deletes the named attribute, provided the object allows it. For
example, ``delattr(x, 'foobar')`` is equivalent to ``del x.foobar``. example, ``delattr(x, 'foobar')`` is equivalent to ``del x.foobar``.
*name* need not be a Python identifier (see :func:`setattr`).
.. _func-dict: .. _func-dict:
@ -746,6 +747,7 @@ are always available. They are listed here in alphabetical order.
value of that attribute. For example, ``getattr(x, 'foobar')`` is equivalent to 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 ``x.foobar``. If the named attribute does not exist, *default* is returned if
provided, otherwise :exc:`AttributeError` is raised. provided, otherwise :exc:`AttributeError` is raised.
*name* need not be a Python identifier (see :func:`setattr`).
.. note:: .. note::
@ -1598,6 +1600,12 @@ are always available. They are listed here in alphabetical order.
object allows it. For example, ``setattr(x, 'foobar', 123)`` is equivalent to object allows it. For example, ``setattr(x, 'foobar', 123)`` is equivalent to
``x.foobar = 123``. ``x.foobar = 123``.
*name* need not be a Python identifier as defined in :ref:`identifiers`
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:: .. note::
Since :ref:`private name mangling <private-name-mangling>` happens at Since :ref:`private name mangling <private-name-mangling>` happens at