misguiding docs in 2.3's UserDict ?
John Lenton
jlenton at gmail.com
Tue Jul 6 12:24:11 EDT 2004
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?
--
John Lenton (jlenton at gmail.com) -- Random fortune:
bash: fortune: command not found
More information about the Python-list
mailing list