mirror of
https://github.com/python/cpython.git
synced 2025-08-31 05:58:33 +00:00
bpo-31787: Prevent refleaks when calling __init__() more than once (GH-3995)
This commit is contained in:
parent
aec7532ed3
commit
d019bc8319
13 changed files with 105 additions and 19 deletions
|
@ -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"""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue