This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author ronaldoussoren
Recipients barry, ethan.furman, ronaldoussoren
Date 2013-07-22.06:52:00
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1374475920.86.0.825491178853.issue18510@psf.upfronthosting.co.za>
In-reply-to
Content
As mentioned on python-dev the current behavior seems sane.

1) Just like __getitem__ and __setitem__, __contains__ raises an 
   exception when the key value cannot be used as a key (which normally
   is a programming error)

2) There are values that compare equal and where one of them is 
   hashable and the other is not, such a set() and frozenset() with
   the same contents. If would be strange if
 
      set([1,2]) in { frozenset([1,2]): 'a' }

   returned False, even though the value is equal to a key in the 
   dictionary.


BTW. I've always interpreted "key in a_dict" as 

       try:
           a_dict[key]
           return True
       except KeyError:
           return False

(and not as equivalent to "key in a_dict.keys()").

(Also, if this behavior were to be changed this would be a new feature and as such could only be added to 3.4 and would IMHO require a PEP)
History
Date User Action Args
2013-07-22 06:52:00ronaldoussorensetrecipients: + ronaldoussoren, barry, ethan.furman
2013-07-22 06:52:00ronaldoussorensetmessageid: <1374475920.86.0.825491178853.issue18510@psf.upfronthosting.co.za>
2013-07-22 06:52:00ronaldoussorenlinkissue18510 messages
2013-07-22 06:52:00ronaldoussorencreate