mirror of
https://github.com/python/cpython.git
synced 2025-07-30 22:54:16 +00:00
[3.13] gh-125590: Allow FrameLocalsProxy to delete and pop keys from extra locals (GH-125616) (#125797)
gh-125590: Allow FrameLocalsProxy to delete and pop keys from extra locals (GH-125616)
(cherry picked from commit 5b7a872b26
)
Co-authored-by: Tian Gao <gaogaotiantian@hotmail.com>
This commit is contained in:
parent
ace5478673
commit
829d650ccb
3 changed files with 99 additions and 8 deletions
|
@ -399,15 +399,41 @@ class TestFrameLocals(unittest.TestCase):
|
|||
def test_delete(self):
|
||||
x = 1
|
||||
d = sys._getframe().f_locals
|
||||
with self.assertRaises(TypeError):
|
||||
|
||||
# This needs to be tested before f_extra_locals is created
|
||||
with self.assertRaisesRegex(KeyError, 'non_exist'):
|
||||
del d['non_exist']
|
||||
|
||||
with self.assertRaises(KeyError):
|
||||
d.pop('non_exist')
|
||||
|
||||
with self.assertRaisesRegex(ValueError, 'local variables'):
|
||||
del d['x']
|
||||
|
||||
with self.assertRaises(AttributeError):
|
||||
d.clear()
|
||||
|
||||
with self.assertRaises(AttributeError):
|
||||
with self.assertRaises(ValueError):
|
||||
d.pop('x')
|
||||
|
||||
with self.assertRaises(ValueError):
|
||||
d.pop('x', None)
|
||||
|
||||
# 'm', 'n' is stored in f_extra_locals
|
||||
d['m'] = 1
|
||||
d['n'] = 1
|
||||
|
||||
with self.assertRaises(KeyError):
|
||||
d.pop('non_exist')
|
||||
|
||||
del d['m']
|
||||
self.assertEqual(d.pop('n'), 1)
|
||||
|
||||
self.assertNotIn('m', d)
|
||||
self.assertNotIn('n', d)
|
||||
|
||||
self.assertEqual(d.pop('n', 2), 2)
|
||||
|
||||
@support.cpython_only
|
||||
def test_sizeof(self):
|
||||
proxy = sys._getframe().f_locals
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue