From 802b645e81a72399a7ef47ef000d468c775dcd3e Mon Sep 17 00:00:00 2001 From: Mark Shannon Date: Tue, 2 Feb 2021 14:59:15 +0000 Subject: 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: ... --- Lib/test/test_bool.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'Lib') diff --git a/Lib/test/test_bool.py b/Lib/test/test_bool.py index 7b3a3859e08..bec44d0b9c5 100644 --- a/Lib/test/test_bool.py +++ b/Lib/test/test_bool.py @@ -354,6 +354,22 @@ def test_real_and_imag(self): 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) -- cgit v1.2.3-65-gdbad