Inconsistency in dictionary behaviour: dict(dict) not calling __setitem__
Raymond Hettinger
python at rcn.com
Tue Dec 12 23:17:53 EST 2006
[Almad]
> I discovered this behaviour in dictionary which I find confusing. In
> SneakyLang, I've tried to extend dictionary so it visits another class
> after something is added:
>
> class RegisterMap(dict):
> def __setitem__(self, k, v):
> dict.__setitem__(self, k,v)
> self[k].visit_register_map(self)
>
>
> However, when constructing dictionary with dictionary in constructor
> like d = RegisterMap({'k':'v'}), __setitem__ is not called,
Try subclassing from UserDict.DictMixin.
Raymond
More information about the Python-list
mailing list