mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
gh-96397: Document that attributes need not be identifiers (#96454)
Co-authored-by: C.A.M. Gerlach <CAM.Gerlach@Gerlach.CAM>
This commit is contained in:
parent
0179a82caa
commit
9a11ed8e50
2 changed files with 17 additions and 2 deletions
|
@ -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`).
|
||||
|
||||
|
||||
.. _func-dict:
|
||||
|
@ -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`).
|
||||
|
||||
.. note::
|
||||
|
||||
|
@ -1582,6 +1584,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`
|
||||
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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue