Issue 37585: Comparing PyDictValues does not give expected results (original) (raw)

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

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 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: https://mail.python.org/archives/list/python-dev@python.org/thread/R2MPDTTMJXAF54SICFSAWPPCCEWAJ7WF/#723CHZBH4ZBKQJOOPXFFX3HYSPDBPDPR

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 https://mail.python.org/archives/list/python-dev@python.org/message/K3SYX4DER3WAOWGQ4SPKCKXSXLXTIVAQ/). A month ago, I opened to PR to add the clarification to the documentation for dict.values(): https://github.com/python/cpython/pull/14954/files.

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) https://github.com/python/cpython/commit/6472ece5a0fe82809d3aa0ffb281796fcd252d76

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) https://github.com/python/cpython/commit/3cd147bf599f116593dc06ed7dfe948b759aabd3

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) https://github.com/python/cpython/commit/690a16d455603500a0c6df0bd87e49c9b37a6950

History

Date

User

Action

Args

2022-04-11 14:59:18

admin

set

github: 81766

2019-09-11 10:46:55

miss-islington

set

messages: +

2019-09-11 10:45:57

miss-islington

set

nosy: + miss-islington
messages: +

2019-09-11 10:03:37

brett.cannon

set

status: open -> closed
stage: patch review -> resolved

2019-09-11 10:01:59

miss-islington

set

pull_requests: + <pull%5Frequest15550>

2019-09-11 10:01:53

miss-islington

set

pull_requests: + <pull%5Frequest15549>

2019-09-11 10:01:45

brett.cannon

set

messages: +

2019-08-23 21:35:38

aeros

set

stage: resolved -> patch review

2019-08-23 08:23:10

aeros

set

status: closed -> open

messages: +

2019-07-26 05:35:02

aeros

set

nosy: + brett.cannon
messages: +

2019-07-26 05:31:33

aeros

set

nosy: + aeros
messages: +

2019-07-26 05:28:32

aeros

set

pull_requests: + <pull%5Frequest14723>

2019-07-13 12:49:40

serhiy.storchaka

set

status: 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:58

xtreak

set

nosy: + xtreak, methane
messages: +

2019-07-13 12:04:11

python-dev

set

keywords: + patch
stage: patch review
pull_requests: + <pull%5Frequest14531>

2019-07-13 11:58:48

Kristian Klette

create