[issue10242] unittest's assertItemsEqual() method makes too many assumptions about its input

Michael Foord report at bugs.python.org
Tue Nov 2 02:40:18 CET 2010

Michael Foord <michael at voidspace.org.uk> added the comment:

On Python-dev Nick Coghlan suggests a fix for the fast-path that would allow us to keep it whilst fixing this bug (not tested yet but adding this note not to lose it). The issue of the name of this method is in 10273.

Looking at assertItemsEqual, I'd be inclined to insert a check that falls back to the "unorderable_list_difference" approach in the case where "expected != sorted(reversed(expected))".

As far as I can tell, that check is a valid partial ordering detector
for any sequence that contains one or more pairs of items for which
LT, EQ and GE are all False:

>>> seq = [{1}, {2}]
>>> seq[0] < seq[1]
>>> seq[0] == seq[1]
>>> seq[0] > seq[1]
>>> sorted(seq)
[{1}, {2}]
>>> sorted(reversed(sorted(seq)))
[{2}, {1}]

Obviously, if the sequence doesn't contain any such items (e.g. all
subsets of each other), then it will look like a total ordering and
use the fast path. I see that as an upside :)


Python tracker <report at bugs.python.org>

More information about the Python-bugs-list mailing list