diff options
author | Victor Stinner <vstinner@python.org> | 2024-08-06 21:01:44 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-06 21:01:44 (GMT) |
commit | 4767a6e31c0550836b2af45d27e374e721f0c4e6 (patch) | |
tree | ac83bad530ad3f874446adb1c51311bacec48d89 /Lib/test | |
parent | 5b8a6c5186be299d96dd483146dc6ea737ffdfe7 (diff) | |
download | cpython-4767a6e31c0550836b2af45d27e374e721f0c4e6.zip cpython-4767a6e31c0550836b2af45d27e374e721f0c4e6.tar.gz cpython-4767a6e31c0550836b2af45d27e374e721f0c4e6.tar.bz2 |
gh-122728: Fix SystemError in PyEval_GetLocals() (#122735)
Fix PyEval_GetLocals() to avoid SystemError ("bad argument to
internal function"). Don't redefine the 'ret' variable in the if
block.
Add an unit test on PyEval_GetLocals().
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_capi/test_misc.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/Lib/test/test_capi/test_misc.py b/Lib/test/test_capi/test_misc.py index 5c4547d..be6fe0c 100644 --- a/Lib/test/test_capi/test_misc.py +++ b/Lib/test/test_capi/test_misc.py @@ -1157,6 +1157,19 @@ class CAPITest(unittest.TestCase): gen = genf() self.assertEqual(_testcapi.gen_get_code(gen), gen.gi_code) + def test_pyeval_getlocals(self): + # Test PyEval_GetLocals() + x = 1 + self.assertEqual(_testcapi.pyeval_getlocals(), + {'self': self, + 'x': 1}) + + y = 2 + self.assertEqual(_testcapi.pyeval_getlocals(), + {'self': self, + 'x': 1, + 'y': 2}) + @requires_limited_api class TestHeapTypeRelative(unittest.TestCase): |