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 <rep...@bugs.python.org>
<http://bugs.python.org/issue22192>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to