diff options
author | Mark Shannon <mark@hotpy.org> | 2021-02-02 14:59:15 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-02 14:59:15 (GMT) |
commit | 802b645e81a72399a7ef47ef000d468c775dcd3e (patch) | |
tree | 914f0e42d0231ae52caf1a436d269cff284631f5 /Lib/test/test_bool.py | |
parent | 9eb11a139fac5514d8456626806a68b3e3b7eafb (diff) | |
download | cpython-802b645e81a72399a7ef47ef000d468c775dcd3e.zip cpython-802b645e81a72399a7ef47ef000d468c775dcd3e.tar.gz cpython-802b645e81a72399a7ef47ef000d468c775dcd3e.tar.bz2 |
Only eliminate jumps to successor block if jump is unconditional. (GH-24417)
* Prevents elimination of the sole test of a value in statements like:
if x or True: ...
Diffstat (limited to 'Lib/test/test_bool.py')
-rw-r--r-- | Lib/test/test_bool.py | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/Lib/test/test_bool.py b/Lib/test/test_bool.py index 7b3a385..bec44d0 100644 --- a/Lib/test/test_bool.py +++ b/Lib/test/test_bool.py @@ -354,6 +354,22 @@ class BoolTest(unittest.TestCase): self.assertIs(type(False.real), int) self.assertIs(type(False.imag), int) + def test_bool_called_at_least_once(self): + class X: + def __init__(self): + self.count = 0 + def __bool__(self): + self.count += 1 + return True + + def f(x): + if x or True: + pass + + x = X() + f(x) + self.assertGreaterEqual(x.count, 1) + def test_main(): support.run_unittest(BoolTest) |