Thanks to everybody for replies, I'm now satisfied ^_^
Almad
--
http://mail.python.org/mailman/listinfo/python-list
[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]
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
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
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
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
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