[issue1475692] replacing obj.__dict__ with a subclass of dict

Torsten Landschoff report at bugs.python.org
Fri Jan 29 11:16:30 EST 2016


Torsten Landschoff added the comment:

I just bumped into this issue because I was shown by a colleague that my implementation of immutable objects (by replacing __dict__ with an ImmutableDict that inherits from dict and blocks write accesses) is ineffective - ouch!

I'd expect that Python either rejects subclasses of dict for obj.__dict__ or actually implements accessing correctly. Especially since the enum module created the impression for me that replacing __dict__ is a viable approach (enum.py uses __prepare__ in the meta class to provide a different dict class for enum types, just found https://www.python.org/dev/peps/pep-3115/).

Interestingly the PEP 3115 example code notes the following:

# Note that we replace the classdict with a regular
# dict before passing it to the superclass, so that we
# don't continue to record member names after the class
# has been created.

----------
nosy: +torsten

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


More information about the Python-bugs-list mailing list