ppperry added the comment:

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 ...

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue28685>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to