[issue39746] Inappropriate short circuit relating to inequality comparison and membership test

2020-02-24 Thread Tim Peters


Tim Peters  added the comment:

Orion, you're using the interface as intended :-)

While it's too late to change now, if Python started over from scratch I'd 
argue to leave "in" and "not in" out of this feature - chaining them is 
_usually_ an unintended behavior.

Then again, sometimes it is slightly useful.  For example, if I want to know if 
`n` is in a set of primes, but isn't even,

if 2 != n in some_set_of_primes:

does the job succinctly.  But not really "Pythonically", since even experienced 
Python programmers may scratch their heads when reading it :-(

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39746] Inappropriate short circuit relating to inequality comparison and membership test

2020-02-24 Thread Eryk Sun


Eryk Sun  added the comment:

For reference see the section on comparisons in the language reference:

https://docs.python.org/3/reference/expressions.html#comparisons

--
nosy: +eryksun
resolution:  -> not a bug

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39746] Inappropriate short circuit relating to inequality comparison and membership test

2020-02-24 Thread Orion Fisher


Orion Fisher  added the comment:

Ah, I see, thank you for the clear explanation.

Chaining is so intuitive in the case it is always introduced with, yet I never 
knew it applied so generally.

(New to the interface so I hope this is indeed where I must reply.)

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39746] Inappropriate short circuit relating to inequality comparison and membership test

2020-02-24 Thread Orion Fisher


Change by Orion Fisher :


--
stage:  -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39746] Inappropriate short circuit relating to inequality comparison and membership test

2020-02-24 Thread Tim Peters


Tim Peters  added the comment:

"!=" and "in" are comparison operators in Python, and _all_ comparison 
operators "chain".  That is,

x < y < z

means

x < y and y < z

(although y is evaluated only once), and in the same way

True != True in [False, False]

means

True != True and True in [False, False]

--
nosy: +tim.peters

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39746] Inappropriate short circuit relating to inequality comparison and membership test

2020-02-24 Thread Orion Fisher


New submission from Orion Fisher :

I found a strange issue with how the interpreter produces bytecode for an 
expression like True != True in [False, False].

Reading it, one would expect the value of the expression to be True, whether 
the inequality comparison is evaluated first, or the membership test is 
evaluated first. Indeed, when parentheses are used to control the order of 
execution these results do occur.

However, without any parentheses, the result is False. The underlying cause 
seems to be in a short circuit which is dependent on the inequality comparison, 
seen in the JUMP_IF_FALSE_OR_POP instruction.

This expression is very synthetic, but I am submitting this bug under the worry 
that it speaks to a more significant error in the bytecode produced for 
inequality tests (or membership tests).

--
components: Interpreter Core
files: bug_occurence.py
messages: 362612
nosy: Orion Fisher
priority: normal
severity: normal
status: open
title: Inappropriate short circuit relating to inequality comparison and 
membership test
type: behavior
versions: Python 3.8
Added file: https://bugs.python.org/file48911/bug_occurence.py

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com