[docs] [issue25205] setattr accepts invalid identifiers

R. David Murray report at bugs.python.org
Wed Sep 23 20:10:41 CEST 2015


R. David Murray added the comment:

I wouldn't call the sendfile case troublesome.  'in' is a keyword, so if you want to use it in function arguments, you have to pass it as a string.  Perfectly logical :)

IIRC pypy uses an optimized dictionary if there are no non-identifier keywords in the attribute __dict__.  I *think* it supports non-identifiers by falling back to a slower implementation, but I could be wrong.  I seem to remember a discussion where it was ruled that the fact that CPython's default __dict__ accepts non-identifiers is a CPython implementation detail and code should not rely on it working...but of course some code does, so we can't "fix" it :).

If I'm remembering right, and if __dict__'s permissiveness is not noted as a CPython implementation detail in the language reference, it should be, but I would expect that it is since that discussion was one of the ones that triggered the introduction such documentation notes.

But, as MvL pointed out, setattr does *not* have this restriction, even if the python implementation rejects it for default __dicts__, because an object can do anything it wants during in its __setattr__ method, and this is an important (and used in the wild!) feature of the language.

----------
nosy: +r.david.murray

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue25205>
_______________________________________


More information about the docs mailing list