On Sun, 16 Jun 2019 at 12:54, Franklin? Lee <leewangzhong+pyt...@gmail.com> wrote: > > On Sat, Jun 15, 2019 at 10:26 PM Guido van Rossum <gu...@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 _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/SYGYTDAZQSSPTHHMHVUY4TRVECDII4SK/ Code of Conduct: http://python.org/psf/codeofconduct/