28.09.20 16:31, Samuel Freilich via Python-ideas пише:
> 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'".)

The code which raises TypeError does not know whether it was called
internally by dict or set method or explicitly by hash(). So neither the
type of container, nor operation are known. And it may be raised when
the key is a tuple which contains a list, that contradicts the proposed
error message.
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/[email protected]/message/7EVB4OKTTL6AQN2MAVNQLV3RJHE2IAI5/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to