diff options
author | Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com> | 2021-02-02 21:06:57 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-02 21:06:57 (GMT) |
commit | 2edaf6a4fb7e20324dde1423232f07211347f092 (patch) | |
tree | 90d57217283933a1ff5bda10f1dab329c4383745 /Doc/library/functions.rst | |
parent | bb739ec922c6992a2be38f9fd3c544c2cc322dde (diff) | |
download | cpython-2edaf6a4fb7e20324dde1423232f07211347f092.zip cpython-2edaf6a4fb7e20324dde1423232f07211347f092.tar.gz cpython-2edaf6a4fb7e20324dde1423232f07211347f092.tar.bz2 |
bpo-8264: Document hasattr and getattr behavior for private attributes (GH-23513)
Clarify ``getattr`` and ``setattr`` requirements for accessing name-mangled attributes
Co-Authored-By: Catalin Iacob <iacobcatalin@gmail.com>
Diffstat (limited to 'Doc/library/functions.rst')
-rw-r--r-- | Doc/library/functions.rst | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/Doc/library/functions.rst b/Doc/library/functions.rst index f84353c..55dd3f0 100644 --- a/Doc/library/functions.rst +++ b/Doc/library/functions.rst @@ -693,6 +693,13 @@ are always available. They are listed here in alphabetical order. ``x.foobar``. If the named attribute does not exist, *default* is returned if provided, otherwise :exc:`AttributeError` is raised. + .. note:: + + Since :ref:`private name mangling <private-name-mangling>` happens at + compilation time, one must manually mangle a private attribute's + (attributes with two leading underscores) name in order to retrieve it with + :func:`getattr`. + .. function:: globals() @@ -1512,6 +1519,13 @@ 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``. + .. note:: + + Since :ref:`private name mangling <private-name-mangling>` happens at + compilation time, one must manually mangle a private attribute's + (attributes with two leading underscores) name in order to set it with + :func:`setattr`. + .. class:: slice(stop) slice(start, stop[, step]) |