mirror of
https://github.com/python/cpython.git
synced 2025-07-23 03:05:38 +00:00
gh-124513: Check args in framelocalsproxy_new() (#124515)
Fix a crash in FrameLocalsProxy constructor: check the number of arguments.
This commit is contained in:
parent
0d9d56c4e4
commit
d6954b6421
3 changed files with 43 additions and 3 deletions
|
@ -494,6 +494,27 @@ class TestFrameLocals(unittest.TestCase):
|
|||
with self.assertRaises(TypeError):
|
||||
proxy[obj] = 0
|
||||
|
||||
def test_constructor(self):
|
||||
FrameLocalsProxy = type([sys._getframe().f_locals
|
||||
for x in range(1)][0])
|
||||
self.assertEqual(FrameLocalsProxy.__name__, 'FrameLocalsProxy')
|
||||
|
||||
def make_frame():
|
||||
x = 1
|
||||
y = 2
|
||||
return sys._getframe()
|
||||
|
||||
proxy = FrameLocalsProxy(make_frame())
|
||||
self.assertEqual(proxy, {'x': 1, 'y': 2})
|
||||
|
||||
# constructor expects 1 frame argument
|
||||
with self.assertRaises(TypeError):
|
||||
FrameLocalsProxy() # no arguments
|
||||
with self.assertRaises(TypeError):
|
||||
FrameLocalsProxy(123) # wrong type
|
||||
with self.assertRaises(TypeError):
|
||||
FrameLocalsProxy(frame=sys._getframe()) # no keyword arguments
|
||||
|
||||
|
||||
class FrameLocalsProxyMappingTests(mapping_tests.TestHashMappingProtocol):
|
||||
"""Test that FrameLocalsProxy behaves like a Mapping (with exceptions)"""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue