mirror of
https://github.com/python/cpython.git
synced 2025-11-25 04:34:37 +00:00
Fix:
[ 1229429 ] missing Py_DECREF in PyObject_CallMethod Add a test in test_enumerate, which is a bit random, but suffices (reversed_new calls PyObject_CallMethod under some circumstances).
This commit is contained in:
parent
208eec2cad
commit
0edc7a03e2
3 changed files with 36 additions and 8 deletions
|
|
@ -1,4 +1,5 @@
|
|||
import unittest
|
||||
import sys
|
||||
|
||||
from test import test_support
|
||||
|
||||
|
|
@ -175,6 +176,25 @@ class TestReversed(unittest.TestCase):
|
|||
self.assertRaises(TypeError, reversed)
|
||||
self.assertRaises(TypeError, reversed, [], 'extra')
|
||||
|
||||
def test_bug1229429(self):
|
||||
# this bug was never in reversed, it was in
|
||||
# PyObject_CallMethod, and reversed_new calls that sometimes.
|
||||
if not hasattr(sys, "getrefcount"):
|
||||
return
|
||||
def f():
|
||||
pass
|
||||
r = f.__reversed__ = object()
|
||||
rc = sys.getrefcount(r)
|
||||
for i in range(10):
|
||||
try:
|
||||
reversed(f)
|
||||
except TypeError:
|
||||
pass
|
||||
else:
|
||||
self.fail("non-callable __reversed__ didn't raise!")
|
||||
self.assertEqual(rc, sys.getrefcount(r))
|
||||
|
||||
|
||||
def test_main(verbose=None):
|
||||
testclasses = (EnumerateTestCase, SubclassTestCase, TestEmpty, TestBig,
|
||||
TestReversed)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue