[issue45542] Using multiple comparison operators can cause performance issues

Dennis Sweeney report at bugs.python.org
Wed Oct 20 19:02:09 EDT 2021


Dennis Sweeney <sweeney.dennis650 at gmail.com> added the comment:

The PR changes behavior slightly:

def f():
    class A:
        def __lt__(self, other):
            nonlocal x
            x += 100
            return True
    a = A()
    x = 1
    print(a < x < 10)
    x = 1
    print(a < x and x < 10)

### Before ###
>>> f()
True
False

### After ###
>>> f()
False
False


So strictly speaking, this would be backwards-incompatible. But morally, I am not totally sure.

----------
nosy: +Dennis Sweeney

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue45542>
_______________________________________


More information about the Python-bugs-list mailing list