misguiding docs in 2.3's UserDict ?

Discussion in 'Python' started by John Lenton, Jul 6, 2004.

  1. John Lenton

    John Lenton Guest

    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 () -- Random fortune:
    bash: fortune: command not found
    John Lenton, Jul 6, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andreas Kuntzagk
    Replies:
    1
    Views:
    344
    Steven Taschuk
    Jul 22, 2003
  2. Alex Martelli

    UserDict question

    Alex Martelli, Nov 4, 2003, in forum: Python
    Replies:
    2
    Views:
    302
    Guyon Morée
    Nov 4, 2003
  3. Uwe Mayer

    UserDict deprecated

    Uwe Mayer, Jan 1, 2005, in forum: Python
    Replies:
    8
    Views:
    554
    Steve Holden
    Jan 3, 2005
  4. Steven Bethard
    Replies:
    8
    Views:
    393
    Nick Coghlan
    Jan 5, 2005
  5. KYG
    Replies:
    2
    Views:
    884
    Ian Collins
    Aug 18, 2008
Loading...

Share This Page