Seeing as dict_values
has been the only builtin subclass of abc.Hashable
which has a broken __eq__
method I've ran into so far, it makes me think it's a bug. While this issue is something most people will never encounter, if I didn't set my tests up just right for my pickleable lru cache I'm making, I would have missed this.
Not only is it illogical, it is confusing to beginners because for all other builtin containers whose __repr__
compares equal, the objects compare equal. The following results are identical in versions 3.3, 3.4, 3.5, and 3.6: (and even in the pure python version of collections.OrderedDict
from 3.3).
>>> a = {1:1}
>>> b = {1:1}
>>> a == b
True
>>> a.items() == b.items()
True
>>> a.keys() == b.keys()
True
>>> a.values() == b.values()
False
>>> x, y = a.values(), b.values()
>>> x == y
False
>>> list(a.values()) == list(b.values())
True
>>> blank = {}
>>> for i in range(10):
blank[{}.values()] = i
>>> blank
{dict_values([]): 0, dict_values([]): 1, dict_values([]): 2, dict_values([]): 3, dict_values([]): 4, dict_values([]): 5, dict_values([]): 6, dict_values([]): 7, dict_values([]): 8, dict_values([]): 9}