[New-bugs-announce] [issue25732] functools.total_ordering does not correctly implement not equal behaviour

David Seddon report at bugs.python.org
Wed Nov 25 08:12:49 EST 2015


New submission from David Seddon:

The documentation for functools.total_ordering states that rich comparison can be enabled on a class by specifying an __eq__ method, and one of __lt__(), __le__(), __gt__(), or __ge__().  If these instructions are followed, this results in an incorrect evaluation of the not equal operator:

Here's an example:

    from functools import total_ordering

    @total_ordering
    class Value(object):

        def __init__(self, value):
            self.value = value
    
        def __eq__(self, other):
            return self.value == other.value
    
        def __lt__(self, other):
            return self.value < other.value

 
    >>> a = Value(3)
    >>> b = Value(3)
    >>> a == b
    True
    >>> a != b
    True

I've tested this on 2.7.10.
 
Either the documentation or the behaviour should be corrected.

https://docs.python.org/2/library/functools.html#functools.total_ordering

----------
messages: 255339
nosy: David Seddon
priority: normal
severity: normal
status: open
title: functools.total_ordering does not correctly implement not equal behaviour
type: behavior
versions: Python 2.7

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue25732>
_______________________________________


More information about the New-bugs-announce mailing list