[issue44605] functools.total_ordering doesn't work with metaclasses

Glyph Lefkowitz report at bugs.python.org
Thu Aug 5 14:39:09 EDT 2021


Glyph Lefkowitz <glyph at twistedmatrix.com> added the comment:

> Do you all have preference for 1) expanding the range of use cases to cover metaclasses but incurring a performance hit for common cases, or 2) leaving it as-is and documenting that it doesn't work for metaclasses?

If we do need the slow approach for the meta-type case, (i.e.: type(self).__lt__(other)) then why not decide on implementation at decoration time? The decorator has enough information to know if this strategy is necessary and can put different special methods in place.

(But also, wouldn't 'from operator import lt ... lt(self, other)' be a bit faster, and also more general, just because it's doing specialized dispatch in C rather than an additional Python function call / method dispatch?  I have not benchmarked myself, so please ignore if you've already tested this.)

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue44605>
_______________________________________


More information about the Python-bugs-list mailing list