bpo-31787: Prevent refleaks when calling __init__() more than once (GH-3995)

This commit is contained in:
Oren Milman 2018-02-13 12:28:33 +02:00 committed by INADA Naoki
parent aec7532ed3
commit d019bc8319
13 changed files with 105 additions and 19 deletions

View file

@ -3,6 +3,7 @@
import sys
import unittest
from test import support
class PropertyBase(Exception):
pass
@ -173,6 +174,16 @@ class PropertyTests(unittest.TestCase):
sub.__class__.spam.__doc__ = 'Spam'
self.assertEqual(sub.__class__.spam.__doc__, 'Spam')
@support.refcount_test
def test_refleaks_in___init__(self):
gettotalrefcount = support.get_attribute(sys, 'gettotalrefcount')
fake_prop = property('fget', 'fset', 'fdel', 'doc')
refs_before = gettotalrefcount()
for i in range(100):
fake_prop.__init__('fget', 'fset', 'fdel', 'doc')
self.assertAlmostEqual(gettotalrefcount() - refs_before, 0, delta=10)
# Issue 5890: subclasses of property do not preserve method __doc__ strings
class PropertySub(property):
"""This is a subclass of property"""