[Python-ideas] a in x or in y

Chris Angelico rosuav at gmail.com
Fri Feb 14 11:40:03 CET 2014


On Fri, Feb 14, 2014 at 9:20 PM, Steven D'Aprano <steve at pearwood.info> wrote:
> I would rather be conservative about adding new syntax in this way. It's
> easier to generalise later than to make it less general. I don't mind
> chaining "in" or "not in", I mind a bit that one might extend that to
> other comparisons, and I *really strongly dislike* that one might write
> something like this without the compiler complaining:
>
> x + 23 or * 2

Maybe, but I find it easier to explain if it's simply "and/or followed
by a binary operator" rather than specifically a function of "[not]
in". Maybe require that it be only comparison operators? That excludes
the example you give (which I agree is insane), and also prevents the
ambiguity of + and - in their unary forms, but would allow this:

inside = 1 < x < 5
outside = x <= 1 or >= 5

In each case, x is written only once. We already have chained
comparisons which implicitly require both conditions; this would allow
an either-or without negating all conditions and putting a big fat
"not" around the outside of it.

ChrisA


More information about the Python-ideas mailing list