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

@ -1559,6 +1559,15 @@ order (MRO) for bases """
del cm.x
self.assertNotHasAttr(cm, "x")
@support.refcount_test
def test_refleaks_in_classmethod___init__(self):
gettotalrefcount = support.get_attribute(sys, 'gettotalrefcount')
cm = classmethod(None)
refs_before = gettotalrefcount()
for i in range(100):
cm.__init__(None)
self.assertAlmostEqual(gettotalrefcount() - refs_before, 0, delta=10)
@support.impl_detail("the module 'xxsubtype' is internal")
def test_classmethods_in_c(self):
# Testing C-based class methods...
@ -1614,6 +1623,15 @@ order (MRO) for bases """
del sm.x
self.assertNotHasAttr(sm, "x")
@support.refcount_test
def test_refleaks_in_staticmethod___init__(self):
gettotalrefcount = support.get_attribute(sys, 'gettotalrefcount')
sm = staticmethod(None)
refs_before = gettotalrefcount()
for i in range(100):
sm.__init__(None)
self.assertAlmostEqual(gettotalrefcount() - refs_before, 0, delta=10)
@support.impl_detail("the module 'xxsubtype' is internal")
def test_staticmethods_in_c(self):
# Testing C-based static methods...