[issue28685] Optimizing list.sort() by performing safety checks in advance
ppperry
report at bugs.python.org
Fri Mar 10 22:58:36 EST 2017
ppperry added the comment:
And what about even wackier code like this?
class A(int):
def __lt__(self, other):
print("zebra")
A.__lt__ = A.__false_lt__
return int.__lt__(self, other)
__true_lt__ = __lt__
def __false_lt__(self, other):
print("gizmo")
A.__lt__ = A.__true_lt__
return int.__lt__(self, other)
[A(i) for i in range(20, 5, -1)].sort()
This alternates printing "zebra" and "gizmo" for every comparison, and there is no way to add some sort of caching without changing this behavior.
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue28685>
_______________________________________
More information about the Python-bugs-list
mailing list