> Please recall that chained comparisons such are
> >>> A < B < C
> is to produce simple code when B is not an identifier, but an expression.
For example
> >>> low < len(x) < high
> or
> >>> inner ** 2 < x**2 + y**2 + z**2 < outer**2
> which determines if (x, y, z) is in a spherical shell.

Even in those cases, each individual expression could be stored in a
variable before doing the comparison:

>>> a, b, c = inner ** 2, x**2 + y**2 + z**2, outer**2
>>> a < b and b < c

But then again I don't find the rich boolean comparison operators (<, <=,
>, =>, ==, !=) to be an issue when they're chained together on standard
numeric types such as the above example, particularly when it's the same
operator. IMO, it only becomes difficult to read when the operators start
to become "mixed up"; more so when the objects are not the builtin types
and have overridden operators:

>>> a is b < c in d

Not only do you have to sort out what is happening logically with the
operators, you also have to figure out what those operators actually do for
that particular object. Whether or not that is "readable" might be somewhat
subjective though.

But I think we're probably veering a bit off topic here, the main focus of
this thread is on whether or not "A in B < C" should be permissible syntax.
Although I'm not a fan of the syntax, I don't think it would be worthwhile
for it to raise a SyntaxError for the reasons I mentioned previously. This
seems to be something to either enforce in a linter or manually revise in a
code review process, rather than through the language itself.
_______________________________________________
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/TGS4TRV54E2EB3OQJ5W7FMQ6GHPXJNI7/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to