On Fri, Jun 14, 2019, 13:49 Brett Cannon <brett@python.org> wrote:
I think the logic breaks down with multiple inheritance. If you make C(A, B), then you can say C > A and C > B, but then you can't say A > B or A < B which breaks sorting.
The logic is fine. Classes can be considered as containers of their instances, and that logic is already used with Python's sets. You can even consider intersections and unions of classes (which are already used to express type constraints). That means you can define __contains__ and comparisons for classes, and the logic will be self-consistent. Mathematically, it's just set theory. Regular expression objects can also be considered as computed collections of the strings they match. You can even enumerate these collections. However, the proposed feature will reserve comparison and container operations to the classes-as-instance-containers concept. That means programmers can't use those operators for something else. If they do, their classes will not play nicely with any library that DOES use the feature, even if they themselves don't use the feature. I wonder how many codebases already use comparison and containment in their metaclasses, and how many use them for something OTHER than classes-as-instance-containers.
If you want to know if a B inherits from Base, then I think `Base in B.mro()` will cover that just as succinctly. And if you need to know position you can compare indexes into the MRO.
Using the MRO directly will ignore virtual subclassing. `issubclass` is the right equivalent. I can't imagine a reason to need to know relative positions in the MRO, except in debugging attribute resolution.