J
John Lenton
I've recently used UserDict's DictMixin class, and I've found the docs
are (somewhat) misguiding: it says, amongst other things, that if my
class implements __contains__ some efficiency will be gained; however,
looking at the source I see that what I should do is implement
has_key, as in DictMixin __contains__ is implemented in terms of
has_key and not viceversa, and if I only implement __contains__,
has_key will still set up a try/except and actually attempt to get at
the key (an operation that might be significantly more expensive than
just checking for existance).
Or did I miss something?
are (somewhat) misguiding: it says, amongst other things, that if my
class implements __contains__ some efficiency will be gained; however,
looking at the source I see that what I should do is implement
has_key, as in DictMixin __contains__ is implemented in terms of
has_key and not viceversa, and if I only implement __contains__,
has_key will still set up a try/except and actually attempt to get at
the key (an operation that might be significantly more expensive than
just checking for existance).
Or did I miss something?