![](https://secure.gravatar.com/avatar/664d320baa05c827ff08ed361fe77769.jpg?s=120&d=mm&r=g)
On Sun, 16 Jun 2019 at 12:54, Franklin? Lee <leewangzhong+python@gmail.com> wrote:
On Sat, Jun 15, 2019 at 10:26 PM Guido van Rossum <guido@python.org> wrote:
I don't actually know how viable this proposal is, but given that it's being debated at some length, I'd like to put in my opinion that *if* we're going to define an operator that's (roughly) synonymous with issubclass(), it should be '<:', which is used in other languages (e.g. Scala) and notational systems (https://en.wikipedia.org/wiki/Subtyping). Overloading '<=' would be easier to implement, but would also cause enough confusion that I think we should avoid it at all cost.
Note that making new operators means class containment relationships can't be used as normal comparisons, such as for `sort`, especially of nested comparables such as tuples of classes. I'm not sure how to define a sort key that works even for a simple list of classes, other than to create a wrapper which implements class comparisons.
The subclass relationship between classes defines a partial rather than total order so it can't be used with a normal sorting algorithm. In general sorting a poset requires all-to-all O(N**2) comparison (worst case: only one pair of objects is comparable). You can sort comparable classes with something like: key = cmp_to_key(lambda a, b: issubclass(b, a) - issubclass(a, b)) -- Oscar