mirror of
https://github.com/python/cpython.git
synced 2025-10-17 20:28:43 +00:00
gh-118272: Clear generator frame's locals when the generator is closed (#118277)
Co-authored-by: Thomas Grainger <tagrain@gmail.com>
This commit is contained in:
parent
f7747f73a9
commit
1f16b4ce56
5 changed files with 38 additions and 5 deletions
|
@ -532,6 +532,26 @@ class GeneratorCloseTest(unittest.TestCase):
|
|||
with self.assertRaises(RuntimeError):
|
||||
gen.close()
|
||||
|
||||
def test_close_releases_frame_locals(self):
|
||||
# See gh-118272
|
||||
|
||||
class Foo:
|
||||
pass
|
||||
|
||||
f = Foo()
|
||||
f_wr = weakref.ref(f)
|
||||
|
||||
def genfn():
|
||||
a = f
|
||||
yield
|
||||
|
||||
g = genfn()
|
||||
next(g)
|
||||
del f
|
||||
g.close()
|
||||
support.gc_collect()
|
||||
self.assertIsNone(f_wr())
|
||||
|
||||
|
||||
class GeneratorThrowTest(unittest.TestCase):
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue