Author ppperry
Recipients elliot.gorokhovsky, mdk, ppperry, serhiy.storchaka, tim.peters, vstinner
Date 2017-03-11.15:12:30
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <7c123cfb290ea93447b7e48329c92583.squirrel@neptune.place.org>
In-reply-to <CANZJz4hnawUo2DGfnVZ3KM8ZgM9P1eJviP9Jnc=hye_C2gexCw@mail.gmail.com>
Content
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 ...
History
Date User Action Args
2017-03-11 15:12:31ppperrysetrecipients: + ppperry, tim.peters, vstinner, serhiy.storchaka, mdk, elliot.gorokhovsky
2017-03-11 15:12:31ppperrylinkissue28685 messages
2017-03-11 15:12:30ppperrycreate