On Fri, Jun 14, 2019 at 08:02:15AM -0000, eminbugrasaral--- via Python-ideas
wrote:
> class Base:
> pass
>
> class A(Base):
> pass
[...]
> While we can do `A == B`, or `B == C` or `B == B`, I would expect to
> be able to compare like this as well: `A >= B (if B is subclass or
> itself of A)`, or `B <= C (if B is a subclass or itself of C)`
On the one hand...
1. I do this *a lot* when describing classes. I might say something like
"suppose we have classes A > B > C > D" and I've not yet come across
anyone who doesn't understand what I mean by that. So from that
perspective, I think that enabling > >= < <= as operators which work on
classes themselves is a simple and obvious syntactic shortcut for
variations of issubclass().
2. In its favour, there's no obvious way to test "is a superclass"
without reversing the logic:
# test that A is a SUPERclass of B:
assert issubclass(B, A) # SUBclass !!!
and no simple way to talk about *strict* subclass and superclass
relationships without a verbose compound test:
assert issubclass(parent, child) and child != parent
But on the other hand:
I can't remember the last time I needed to do an issubclass test. If
I've done more than four or five in the last decade, I'd be surprised.
So I am not convinced that this is common enough to deserve syntactic
sugar.
I'd like to hear what people who do a lot of subclass testing think. But
for myself, I don't oppose this, but I'm only every-so-slightly in
favour.
One possible objection which I don't think is a good objection is that
class relationships don't form a trichotomy: given two class A and B, it
is *not true* that one of these must hold:
A == B *or* A > B *or* A < B
Honestly, I don't think that really matters. That trichotomy doesn't
even hold for floats, and it doesn't hold for sets, so I don't think
this will be a problem.
--
Steven
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/ESZLP5ZWA6RYZPSWE4SMIDGXCTBCFT5E/
Code of Conduct: http://python.org/psf/codeofconduct/