[Python-Dev] Why are class dictionaries not accessible? (original) (raw)
Random832 random832 at fastmail.com
Wed Jun 22 10:17:27 EDT 2016
- Previous message (by thread): [Python-Dev] When to use EOFError?
- Next message (by thread): [Python-Dev] Why are class dictionaries not accessible?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
The documentation states: """Objects such as modules and instances have an updateable dict attribute; however, other objects may have write restrictions on their dict attributes (for example, classes use a dictproxy to prevent direct dictionary updates)."""
However, it's not clear from that why direct dictionary updates are undesirable. This not only prevents you from getting a reference to the real class dict (which is the apparent goal), but is also the fundamental reason why you can't use a metaclass to put, say, an OrderedDict in its place - because the type constructor has to copy the dict that was used in class preparation into a new dict rather than using the one that was actually returned by prepare.
[Also, the name of the type used for this is mappingproxy, not dictproxy]
- Previous message (by thread): [Python-Dev] When to use EOFError?
- Next message (by thread): [Python-Dev] Why are class dictionaries not accessible?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]