summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorDennis Sweeney <36520290+sweeneyde@users.noreply.github.com>2023-02-27 10:46:40 (GMT)
committerGitHub <noreply@github.com>2023-02-27 10:46:40 (GMT)
commite3c3f9fec099fe78d2f98912be337d632f6fcdd1 (patch)
treed38597eae9ef4018b063e217f3c30147c09167fb /Lib
parent101a12c5767a8c6ca6e32b8e24a462d2606d24ca (diff)
downloadcpython-e3c3f9fec099fe78d2f98912be337d632f6fcdd1.zip
cpython-e3c3f9fec099fe78d2f98912be337d632f6fcdd1.tar.gz
cpython-e3c3f9fec099fe78d2f98912be337d632f6fcdd1.tar.bz2
gh-102250: Fix double-decref in COMPARE_AND_BRANCH error case (GH-102287)
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_bool.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/Lib/test/test_bool.py b/Lib/test/test_bool.py
index b711ffb..916e22a 100644
--- a/Lib/test/test_bool.py
+++ b/Lib/test/test_bool.py
@@ -319,6 +319,26 @@ class BoolTest(unittest.TestCase):
return -1
self.assertRaises(ValueError, bool, Eggs())
+ def test_interpreter_convert_to_bool_raises(self):
+ class SymbolicBool:
+ def __bool__(self):
+ raise TypeError
+
+ class Symbol:
+ def __gt__(self, other):
+ return SymbolicBool()
+
+ x = Symbol()
+
+ with self.assertRaises(TypeError):
+ if x > 0:
+ msg = "x > 0 was true"
+ else:
+ msg = "x > 0 was false"
+
+ # This used to create negative refcounts, see gh-102250
+ del x
+
def test_from_bytes(self):
self.assertIs(bool.from_bytes(b'\x00'*8, 'big'), False)
self.assertIs(bool.from_bytes(b'abcd', 'little'), True)