Message165983
Amaury, I don't honestly know, I would have proposed something otherwise.
I have been advised on #python (Freenode) not to assign to obj.__dict__ because its behaviour changes between versions and implementations, but I wouldn't know what has changed between CPython version.
One obscure thing is what can be assigned to __dict__. For class dicts no assignment is allowed. Object dicts can be assigned dict objects. If you try to assign a non-dict mapping it will complain.
However you can assign a dict-derived object, something like:
class SillyDict(dict):
def __getitem__(self, key):
return "hello"
obj.__dict__ = SillyDict()
Unfortunately accessing the attributes of obj will still use PyDict_* functions, thus ignoring any magic methods.
PyPy's behavior is slightly different. A class __dict__ attribute still is read only, but you can assign any mapping object to an object __dict__. |
|
Date |
User |
Action |
Args |
2012-07-20 22:37:53 | davide.rizzo | set | recipients:
+ davide.rizzo, amaury.forgeotdarc, Arfrever, docs@python |
2012-07-20 22:37:53 | davide.rizzo | set | messageid: <1342823873.36.0.576466728664.issue15360@psf.upfronthosting.co.za> |
2012-07-20 22:37:52 | davide.rizzo | link | issue15360 messages |
2012-07-20 22:37:52 | davide.rizzo | create | |
|