◐ Shell
clean mode source ↗

Message 289447 - Python tracker

What about if one of the relevant comparison functions is implemented in C?

        class WackyComparator(int):
		def __lt__(self, other):
			elem.__class__ = WackyList2
			return int.__lt__(self, other)

	class WackyList1(list):pass
	class WackyList2(list):
		def __lt__(self, other):
			raise ValueError
	lst =
list(map(WackyList1,[[WackyComparator(3),5],[WackyComparator(4),6],[WackyComparator(7),7]]))
	random.shuffle(lst)
	elem = lst[-1]
	lst.sort()

This code raises ValueError, and caching seems like it would cache the
comparator for WackyList1 objects, which is the same as the comparator for
'list' objects -- and midway through comparison, one of them changes type
to WackyList2, which has its own (broken) comparison function.

Python is very very dynamic ...