Re: Inconsistency in dictionary behaviour: dict(dict) not calling __setitem__

2006-12-14 Thread Almad
Thanks to everybody for replies, I'm now satisfied ^_^ Almad -- http://mail.python.org/mailman/listinfo/python-list

Re: Inconsistency in dictionary behaviour: dict(dict) not calling __setitem__

2006-12-12 Thread Raymond Hettinger
[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]

Re: Inconsistency in dictionary behaviour: dict(dict) not calling __setitem__

2006-12-12 Thread Andrea Griffini
Mitja Trampus wrote: ... > At least, I know it surprised me when I first met this behavior. Or is > my reasoning incorrect? Why len() doesn't call iteritems() ? :-) Kidding apart for example it would be ok for __setitem__ to call either an internal "insert_new_item" or "update_existing_item" de

Re: Inconsistency in dictionary behaviour: dict(dict) not calling __setitem__

2006-12-12 Thread Fredrik Lundh
Mitja Trampus wrote: > I think what was unexpected for the OP is that dict.__init__ > does not use __setitem__ to create its internal structures. you can implement most methods on core objects in terms of other methods. picking one by random, and then complaining that other methods don't use

Re: Inconsistency in dictionary behaviour: dict(dict) not calling __setitem__

2006-12-12 Thread Mitja Trampus
Fredrik Lundh wrote: > Almad wrote: > >> However, when constructing dictionary with dictionary in constructor >> like d = RegisterMap({'k':'v'}), __setitem__ is not called > > why should it do that? dict() is a concrete implementation, not a > template class for the creation of dict-like object

Re: Inconsistency in dictionary behaviour: dict(dict) not calling __setitem__

2006-12-12 Thread Fredrik Lundh
Almad wrote: > However, when constructing dictionary with dictionary in constructor > like d = RegisterMap({'k':'v'}), __setitem__ is not called why should it do that? dict() is a concrete implementation, not a template class for the creation of dict-like objects. > Or should this be consider

Inconsistency in dictionary behaviour: dict(dict) not calling __setitem__

2006-12-12 Thread Almad
Hello, 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