Message 289435 - Python tracker (original) (raw)

Actually, I just ran this in the patched interpreter, and it worked! It printed: zebra gizmo zebra gizmo zebra gizmo zebra gizmo zebra gizmo zebra gizmo zebra gizmo

Inspired by the above result, I ran your counterexample (below) to see if it would work as well: from random import * class ClassAssignmentCanBreakChecks(): def init(self, i): self._i = i def lt (self, other): print('gizmo') last.class = OrdinaryOldInteger return self._i < (other._i if hasattr(other, '_i') else other)

class OrdinaryOldInteger: def init(self, i): self._i = i def lt(self, other): print('rocket') return self._i < (other._i if hasattr(other, '_i') else other) lst = [ClassAssignmentCanBreakChecks(i) for i in range(10)] shuffle(lst) last = lst[-1] lst.sort()

And it did! It printed: gizmo gizmo gizmo gizmo gizmo gizmo gizmo gizmo gizmo gizmo gizmo gizmo gizmo gizmo gizmo gizmo gizmo gizmo gizmo rocket rocket rocket

Note the "rocket" prints at the end; those could not have printed if the compare method didn't change!

Do I have any idea why these tests work? No. But I swear, I just re-made the patched interpeter in the directory where I ran the tests. You will definitely be able to reproduce my results on your system.

Wacky! (seriously though I have no idea why this works, it just... does... I'm scared...)