[New-bugs-announce] [issue12445] dict view values objects are missing tp_richcmp and tp_as_number

Julian report at bugs.python.org
Thu Jun 30 02:03:10 CEST 2011

New submission from Julian <Julian+Python.org at GrayVines.com>:

dict view values() objects are missing tp_richcmp and tp_as_sequence, and the tests for those were incomplete, which means that on 2.7 and 3.2 (and on current head) viewvalues / values objects don't compare correctly. Without indication, I assume this is not the desired behavior.

Looks like the cause is that the dictview_richcompare function was written to expect a set-like object, and nothing was written for values. I've modified it to accept any view object and do the appropriate check.

One thing I'm unsure of, which I'm sure one of you will help with, is what the desired behavior is on what values() view objects actually *should* be equal to. Being that there isn't a multiset object, and that I couldn't find any resource, I assumed that they only should be equal to other values() objects, not any of the other (ordered) containers. If that's incorrect, or if I need to discuss that on the mailing list, please let me know.

A patch to fix both is attached with the correction to the unit test, hope I did this correctly. I assume this needs to be backported to 2.7, but I figured I'd ask about that first. (Test suite runs without errors on current 3.3 head with this patch for me).

dictview_richcompare also needs unit tests for the NotImplemented error that it should return, but I didn't want to convolute this patch, please let me know if I should put that in here, or file another ticket, or neither.


components: Interpreter Core
files: viewvalues_compare.patch
keywords: patch
messages: 139455
nosy: Julian
priority: normal
severity: normal
status: open
title: dict view values objects are missing tp_richcmp and tp_as_number
type: behavior
versions: Python 2.7, Python 3.2, Python 3.3
Added file: http://bugs.python.org/file22518/viewvalues_compare.patch

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list