[issue41114] "TypeError: unhashable type" could often be more clear
Samuel Freilich
report at bugs.python.org
Sun Sep 27 19:11:49 EDT 2020
Samuel Freilich <sfreilich at google.com> added the comment:
> The user already knows
The example I link to in the initial description appears to be one case where the user does not in fact know.
I do think context that this restriction applies to dict key in particular is very relevant. The line could use the same type for both the key and the value in a dict assignment, for example.
> TypeError: unhashable type: 'dict'. Consider using an int, str, tuple, or frozenset.
That seems like a pretty reasonable wording, though I think mentioning "dictionary key" or "set item" specifically still helps.
It could also link to the documentation directly:
https://docs.python.org/3/glossary.html#term-hashable
Though other error messages don't generally follow that pattern.
> Saying it twice doesn't help.
As the comment you were responding to noted, putting it in the type implies there might be additional information in documentation (or at least provides a place in documentation to put that information). TypeError is too general to say something about that specifically:
https://docs.python.org/3/library/exceptions.html#TypeError
----------
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue41114>
_______________________________________
More information about the Python-bugs-list
mailing list