The error message for using a mutable sequence as a set item or map key
seems to frequently confuse Python beginners. The current wording is:

>>> {[1, 2, 3]: [4, 5, 6]}
TypeError: unhashable type: 'list'

The first thing a Google search finds for "unhashable type" is ~4k Stack
Overflow results like:
https://stackoverflow.com/questions/13264511/typeerror-unhashable-type-dict

The message does not include:
* The type on which the operation is performed
* Which input to the operation is the problem
* The word "hashable" verbatim, which appears in the glossary
* A link to https://docs.python.org/3/glossary.html#term-hashable
* A suggestion of what to do instead

For example:
TypeError: dict keys must be hashable (
https://docs.python.org/glossary.html#term-hashable), 'list' is not.
Consider using a primitive type (e.g. int, str) or immutable sequence (e.g.
tuple, frozenset).

(That could be too much stuff, my point is I think there's room for
improvement over "unhashable type: 'list'".)

I filed a bug about this (https://bugs.python.org/issue41114), but it was
closed by a core contributor, who suggested discussing that on this list
instead. While it's true that you can Google the error message and find the
relevant information, I think the error message text would be worth
improving.

Peace,
-Sam
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/B6OMGYIM47OVGOCZLEY3MEUJDFURJRDV/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to