Some people find this legal syntax confusing:

A in B < C

(It means A in B and B < C.)

I feel like most code reviews would not allow this kind of code to be 
checked in, at least without a comment explaining what the code does.  What 
are the motivating reasons for allowing this syntax?  Is there any 
idiomatic code that uses it?

If not, I suggest dividing the comparison operators into two groups:

in, not in, is, is not

and

<, >, <=, >=, ==, !=

and then disallowing chaining of operators from both groups.

For example, still allowed:

A <= B <= C

A in B in C

disallowed:

A < B in C

The advantage of such a change is that there is fewer "gotcha" code.  I 
admit that this code is rarely written, but it can come up.  For example, 
you might write your own comparison operator and then want to see if it's 
working:

A < B is None

returns false if B is not None even if A < B returns None.

Also, in my opinion, the existence is a deterrent to Python and takes away 
from Python's beauty as a language.

The downside of such a change is that the language is more complicated.

As far as implementation goes, this can be done after parsing when the AST 
is checked and errors are raised (from what I remember).

Best,

Neil
_______________________________________________
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/S7NBNTIPUON2N6WGNBCJXBRVAJNFPNPS/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to