A regular python dict forbids attribute access:
>>> d = {}
>>> d.a = 1
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'dict' object has no attribute 'a'
However, a subclass of dict does not forbid attribute access:
>>> class MyDict(dict):
... pass
...
>>> d = MyDict()
>>> d.a = 1
>>> d.a
1
>>> d.__dict__
{'a': 1}
I would have expected subclasses of dict
to also forbid attribute access. If you wanted attribute access in the subclass, I would have thought that you would need to override __setattr__
for example.
What explains why a subclass of dict does not forbid attribute access by default?