[New-bugs-announce] [issue22192] dict_values objects are hashable

Ben Roberts report at bugs.python.org
Wed Aug 13 22:52:43 CEST 2014


New submission from Ben Roberts:

In python 3.4 these result in a TypeError:

  hash({}.keys())

  hash({}.items())

But this succeeds:

  hash({}.values())

The 2.7 backports of these - viewkeys, viewitems, and viewvalues respectively - behave equivalently.

See more discussion on StackOverflow: http://stackoverflow.com/questions/25293912/why-are-some-dict-views-hashable

The cause appears to be that key and item views implement rich comparisons, whereas values views do not.  Therefore dict_view objects use the default id()-based __hash__ implementation.

Possible fix: explicitly set tp_hash to PyObject_HashNotImplemented for PyDictValues_Type - and perhaps for the other two view types as well, for symmetry.

----------
components: Interpreter Core
messages: 225287
nosy: roippi
priority: normal
severity: normal
status: open
title: dict_values objects are hashable
type: behavior
versions: Python 2.7, Python 3.4

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue22192>
_______________________________________


More information about the New-bugs-announce mailing list