bpo-31787: Prevent refleaks when calling __init__() more than once (GH-3995)
(cherry picked from commit d019bc8319ea35e93bf4baa38098ff1b57cd3ee5)
Co-authored-by: Oren Milman <orenmn@gmail.com>
diff --git a/Lib/test/test_property.py b/Lib/test/test_property.py
index 26b7d52..f6f8f5e 100644
--- a/Lib/test/test_property.py
+++ b/Lib/test/test_property.py
@@ -3,6 +3,7 @@
import sys
import unittest
+from test import support
class PropertyBase(Exception):
pass
@@ -173,6 +174,16 @@
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"""