This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author glyph
Recipients glyph
Date 2021-07-12.05:21:04
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1626067265.0.0.995880932731.issue44605@roundup.psfhosted.org>
In-reply-to
Content
Consider the following example that attempts to make a series of types sortable by their class name:




from functools import total_ordering

@total_ordering
class SortableMeta(type):
    def __new__(cls, name, bases, ns):
        return super().__new__(cls, name, bases, ns)

    def __lt__(self, other):
        if not isinstance(other, SortableMeta):
            pass
        return self.__name__ < other.__name__

    def __eq__(self, other):
        if not isinstance(other, SortableMeta):
            pass
        return self.__name__ == other.__name__

class B(metaclass=SortableMeta):
    pass

class A(metaclass=SortableMeta):
    pass


print(A < B)
print(A > B)


This should just print "True", "False", but instead the second comparison raises this exception:

Traceback (most recent call last):
  File "total_ordering_metaclass.py", line 27, in <module>
    print(A > B)
  File "lib/python3.9/functools.py", line 91, in _gt_from_lt
    op_result = self.__lt__(other)
TypeError: expected 1 argument, got 0


The problem here is that functools considers .__special__ to be equivalent to operator.special.  I'm pretty sure this should be invoking "self < other" rather than self.__lt__(other).
History
Date User Action Args
2021-07-12 05:21:05glyphsetrecipients: + glyph
2021-07-12 05:21:05glyphsetmessageid: <1626067265.0.0.995880932731.issue44605@roundup.psfhosted.org>
2021-07-12 05:21:04glyphlinkissue44605 messages
2021-07-12 05:21:04glyphcreate