gh-118921: Add copy() method for FrameLocalsProxy (#118923)

This commit is contained in:
Tian Gao 2024-05-10 15:53:10 -07:00 committed by GitHub
parent b88889e9ff
commit 35c436186b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 29 additions and 3 deletions

View file

@ -371,6 +371,15 @@ class TestFrameLocals(unittest.TestCase):
f_locals['o'] = f_locals['k']
self.assertEqual(o, 'a.b.c')
def test_copy(self):
x = 0
d = sys._getframe().f_locals
d_copy = d.copy()
self.assertIsInstance(d_copy, dict)
self.assertEqual(d_copy['x'], 0)
d_copy['x'] = 1
self.assertEqual(x, 0)
def test_update_with_self(self):
def f():
f_locals = sys._getframe().f_locals
@ -405,9 +414,6 @@ class TestFrameLocals(unittest.TestCase):
def test_unsupport(self):
x = 1
d = sys._getframe().f_locals
with self.assertRaises(AttributeError):
d.copy()
with self.assertRaises(TypeError):
copy.copy(d)