This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: Comparing PyDictValues does not give expected results
Type: behavior Stage: resolved
Components: Library (Lib) Versions:
Status: closed Resolution: duplicate
Dependencies: Superseder: dict view values objects are missing tp_richcmp and tp_as_number
View: 12445
Assigned To: Nosy List: Kristian Klette, aeros, brett.cannon, methane, miss-islington, xtreak
Priority: normal Keywords: patch

Created on 2019-07-13 11:58 by Kristian Klette, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 14737 closed python-dev, 2019-07-13 12:04
PR 14954 merged aeros, 2019-07-26 05:28
PR 15908 merged miss-islington, 2019-09-11 10:01
PR 15909 merged miss-islington, 2019-09-11 10:01
Messages (8)
msg347806 - (view) Author: Kristian Klette (Kristian Klette) * Date: 2019-07-13 11:58
As a user, I expect to be able to compare the different parts a `dict`
in the same manner.

Currently, `PyDictValues` does not implement the `dictview_richcompare`, causing the `__eq__` to always return false, even if the values are identical.

my_dict = {'foo': 'bar'}
dict_copy = my_dict.copy()
other_dict = {'foo': 'bar', 'bar': 1234}

assert my_dict.keys() == my_dict.keys()
assert my_dict.keys() == dict_copy.keys()
assert my_dict.keys() != other_dict.keys()

assert my_dict.items() == my_dict.items()
assert my_dict.items() == dict_copy.items()
assert my_dict.items() != other_dict.items()

assert my_dict.values() == my_dict.values()
assert my_dict.values() == dict_copy.values()
assert my_dict.values() != other_dict.values()

msg347807 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python committer) Date: 2019-07-13 12:36
See also issue12445 which was a similar proposal rejected in the past.
msg348462 - (view) Author: Kyle Stanley (aeros) * (Python committer) Date: 2019-07-26 05:31
Based on the current status of the discussion in python-dev, the most agreed upon solution so far seems to be updating the documentation to mention this behavior, rather than modifying the existing behavior. I opened a PR which updates the documentation for dict.values() to mention this, feel free to leave any suggestions.

python-dev discussion archive:
msg348463 - (view) Author: Kyle Stanley (aeros) * (Python committer) Date: 2019-07-26 05:35
Added Brett to the nosy list since he was the one who suggested a documentation change.
msg350266 - (view) Author: Kyle Stanley (aeros) * (Python committer) Date: 2019-08-23 08:23
Reopening the issue for adding the documentation clarification, that comparing the values view of two dictionaries will always return false (as was suggested in the ML discussion A month ago, I opened to PR to add the clarification to the documentation for dict.values():

It probably went unnoticed because the issue had already been closed (which I hadn't realized at the time).
msg351791 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2019-09-11 10:01
New changeset 6472ece5a0fe82809d3aa0ffb281796fcd252d76 by Brett Cannon (Kyle Stanley) in branch 'master':
bpo-37585: Add clarification regarding comparing dict.values() (GH-14954)
msg351808 - (view) Author: miss-islington (miss-islington) Date: 2019-09-11 10:45
New changeset 3cd147bf599f116593dc06ed7dfe948b759aabd3 by Miss Islington (bot) in branch '3.7':
bpo-37585: Add clarification regarding comparing dict.values() (GH-14954)
msg351809 - (view) Author: miss-islington (miss-islington) Date: 2019-09-11 10:46
New changeset 690a16d455603500a0c6df0bd87e49c9b37a6950 by Miss Islington (bot) in branch '3.8':
bpo-37585: Add clarification regarding comparing dict.values() (GH-14954)
Date User Action Args
2022-04-11 14:59:18adminsetgithub: 81766
2019-09-11 10:46:55miss-islingtonsetmessages: + msg351809
2019-09-11 10:45:57miss-islingtonsetnosy: + miss-islington
messages: + msg351808
2019-09-11 10:03:37brett.cannonsetstatus: open -> closed
stage: patch review -> resolved
2019-09-11 10:01:59miss-islingtonsetpull_requests: + pull_request15550
2019-09-11 10:01:53miss-islingtonsetpull_requests: + pull_request15549
2019-09-11 10:01:45brett.cannonsetmessages: + msg351791
2019-08-23 21:35:38aerossetstage: resolved -> patch review
2019-08-23 08:23:10aerossetstatus: closed -> open

messages: + msg350266
2019-07-26 05:35:02aerossetnosy: + brett.cannon
messages: + msg348463
2019-07-26 05:31:33aerossetnosy: + aeros
messages: + msg348462
2019-07-26 05:28:32aerossetpull_requests: + pull_request14723
2019-07-13 12:49:40serhiy.storchakasetstatus: open -> closed
resolution: duplicate
superseder: dict view values objects are missing tp_richcmp and tp_as_number
stage: patch review -> resolved
2019-07-13 12:36:58xtreaksetnosy: + xtreak, methane
messages: + msg347807
2019-07-13 12:04:11python-devsetkeywords: + patch
stage: patch review
pull_requests: + pull_request14531
2019-07-13 11:58:48Kristian Klettecreate