Skip to content
This repository was archived by the owner on May 3, 2023. It is now read-only.

Commit 7a4e2fa

Browse files
authored
gh-102250: Fix double-decref in COMPARE_AND_BRANCH error case (GH-102287)
1 parent 3ae7010 commit 7a4e2fa

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

test/test_bool.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,26 @@ def __len__(self):
319319
return -1
320320
self.assertRaises(ValueError, bool, Eggs())
321321

322+
def test_interpreter_convert_to_bool_raises(self):
323+
class SymbolicBool:
324+
def __bool__(self):
325+
raise TypeError
326+
327+
class Symbol:
328+
def __gt__(self, other):
329+
return SymbolicBool()
330+
331+
x = Symbol()
332+
333+
with self.assertRaises(TypeError):
334+
if x > 0:
335+
msg = "x > 0 was true"
336+
else:
337+
msg = "x > 0 was false"
338+
339+
# This used to create negative refcounts, see gh-102250
340+
del x
341+
322342
def test_from_bytes(self):
323343
self.assertIs(bool.from_bytes(b'\x00'*8, 'big'), False)
324344
self.assertIs(bool.from_bytes(b'abcd', 'little'), True)

0 commit comments

Comments
 (0)