Skip to content

Commit f47c3de

Browse files
committed
bpo-35105: Document that CPython accepts invalid identifiers
1 parent 99d56b5 commit f47c3de

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

Doc/library/functions.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1388,6 +1388,17 @@ are always available. They are listed here in alphabetical order.
13881388
object allows it. For example, ``setattr(x, 'foobar', 123)`` is equivalent to
13891389
``x.foobar = 123``.
13901390

1391+
.. note::
1392+
1393+
setattr() attempts to update the object with the given attr/value pair.
1394+
Whether this succeeds and what its affect is is determined by the target object.
1395+
If an object's class defines `__slots__`, the attribute may not be writeable.
1396+
If an object's class defines property with a setter method, the *setattr()*
1397+
will trigger the setter method which may or may not actually write the attribute.
1398+
For objects that have a regular dictionary (which is the typical case), the
1399+
*setattr()* call can make any string keyed update allowed by the dictionary
1400+
including keys that aren't valid identifiers -- for example setattr(a, '1', 'one')
1401+
will be the equivalent of vars()['1'] ='one'.
13911402

13921403
.. class:: slice(stop)
13931404
slice(start, stop[, step])

0 commit comments

Comments
 (0)