[New-bugs-announce] [issue3829] Tuple comparison masking exception

Fred L. Drake, Jr. report at bugs.python.org
Wed Sep 10 22:33:00 CEST 2008

New submission from Fred L. Drake, Jr. <fdrake at acm.org>:

There's a strange condition where cmp() of tuples of unorderable values
returns -1 even though using the unorderable values raises an exception.

If I have these two unorderable values, cmp() raises an expected exception:

  >>> s0 = frozenset(['testing 0'])
  >>> s1 = frozenset(['testing 1'])
  >>> cmp(s0, s1)
  Traceback (most recent call last):
    File "<stdin>", line 1, in ?
  TypeError: cannot compare sets using cmp()

Comparing tuples of the values returns -1:

  >>> cmp((s0,), (s1,))

Py3k does raise a TypeError, but the message is indecipherable:

  >>> cmp((s0,), (s1,))
  Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
  TypeError: unorderable types: 'tuple' != 'tuple'

(The Py3k message for the set comparison is the same as for Python 2.)

I believe that this is an error; the exception from the underlying item
comparison should be propagated.

components: Interpreter Core
messages: 72981
nosy: fdrake
severity: normal
status: open
title: Tuple comparison masking exception
type: behavior
versions: Python 2.4, Python 2.5, Python 2.6, Python 3.0

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list