Ronald Oussoren added the comment:

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)

----------
nosy: +ronaldoussoren

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue18510>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to