A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2013-July/127447.html below:

[Python-Dev] dict __contains__ raises TypeError on unhashable input

[Python-Dev] dict __contains__ raises TypeError on unhashable inputBenjamin Peterson benjamin at python.org
Sat Jul 20 09:13:47 CEST 2013
2013/7/19 Ethan Furman <ethan at stoneleaf.us>:
> While working on issue #18508 I stumbled across this:
>
> Traceback (most recent call last):
> ...
>   File "/usr/local/lib/python3.4/enum.py", line 417, in __new__
>     if value in cls._value2member_map:
> TypeError: unhashable type: 'list'
>
> I'll wrap it in a try-except block, but I must admit I was surprised the
> answer wasn't False.  After all, if the input is unhashable then obviously
> it's not in the dict; furthermore, if I were to compare the number 5 with a
> set() I would get False, not a TypeMismatch error, and dict keys are
> basically done by equality, the hash is just (?) a speed-up.

I'm not exactly sure what the last part of that sentence means.

Anyway, it's well established that operations on a key in a dict are
going to involve looking up the key, and thus hashing it. You wouldn't
expect, {}.get(unhashable, None) not to raise, right?



--
Regards,
Benjamin
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4