On Fri, Jun 14, 2019, 13:49 Brett Cannon <br...@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.
_______________________________________________
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/HW7COZRQVVAGIMR6VOMAJKW32FDPVNDM/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to