Author rhettinger
Recipients Windson Yang, chris.jerdonek, docs@python, nedbat, orlnub123, pablogsal, rhettinger, serhiy.storchaka, steven.daprano, terry.reedy, vstinner, xtreak
Date 2018-12-24.07:42:11
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1545637331.58.0.0770528567349.issue35105@roundup.psfhosted.org>
In-reply-to
Content
I don't think we can mark this as an implementation detail for setattr(). The details are downstream and determined by the target object, not by setattr() itself.

Suggested wording:

'''
Note, setattr() attempts to update the object with the given attr/value pair.
Whether this succeeds and what its affect is is determined by the target object.
If an object's class defines `__slots__`, the attribute may not be writeable.
If an object's class defines property with a setter method, the *setattr()*
will trigger the setter method which may or may not actually write the attribute.
For objects that have a regular dictionary (which is the typical case), the
*setattr()* call can make any string keyed update allowed by the dictionary
including keys that aren't valid identifiers -- for example setattr(a, '1', 'one')
will be the equivalent of vars()['1'] ='one'.
This issue has little to do with setattr() and is more related to the fact that instance dictionaries can hold any valid key. In a way, it is no different than a user writing a.__dict__['1'] = 'one'. That has always been allowed and the __dict__ attribute is documented as writeable, so a user is also allowed to write `a.dict = {'1': 'one'}.
'''

In short, we can talk about this in the setattr() docs but it isn't really a setattr() issue. Also, the behavior is effectively guaranteed by the other things users are allowed to do, so there is no merit in marking this as an implementation detail. Non-identifier keys can make it into an instance dictionary via multiple paths that are guaranteed to work.
History
Date User Action Args
2018-12-24 07:42:13rhettingersetrecipients: + rhettinger, terry.reedy, vstinner, nedbat, steven.daprano, chris.jerdonek, docs@python, serhiy.storchaka, pablogsal, Windson Yang, xtreak, orlnub123
2018-12-24 07:42:11rhettingersetmessageid: <1545637331.58.0.0770528567349.issue35105@roundup.psfhosted.org>
2018-12-24 07:42:11rhettingerlinkissue35105 messages
2018-12-24 07:42:11rhettingercreate