Pedro Werneck <[EMAIL PROTECTED]> wrote: > On Wed, 09 Aug 2006 16:51:23 GMT > "David Isaac" <[EMAIL PROTECTED]> wrote: > > > Looking forward: > > Can I count on this independence of __getitem__ and __contains__? > > I would like to understand whether it will be safe to count on this > > behavior. > > With the builtin 'dict' implementation, dict.__contains__() use the > dict_has_key() C function, and does not touch your subclass __getitem__ > python method. I don't think it can be called 'safe'... it may lead to > very inconsistent behavior. It's like overridind both __eq__ and __ge__ > with a different behavior. It's better for you to override > __contains__() too.
I think it's perfectly safe -- that's what defaultdict in Python 2.5 does, after all. Alex -- http://mail.python.org/mailman/listinfo/python-list