Message193506
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) |
|
Date |
User |
Action |
Args |
2013-07-22 06:52:00 | ronaldoussoren | set | recipients:
+ ronaldoussoren, barry, ethan.furman |
2013-07-22 06:52:00 | ronaldoussoren | set | messageid: <1374475920.86.0.825491178853.issue18510@psf.upfronthosting.co.za> |
2013-07-22 06:52:00 | ronaldoussoren | link | issue18510 messages |
2013-07-22 06:52:00 | ronaldoussoren | create | |
|