summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2024-08-06 21:01:44 (GMT)
committerGitHub <noreply@github.com>2024-08-06 21:01:44 (GMT)
commit4767a6e31c0550836b2af45d27e374e721f0c4e6 (patch)
treeac83bad530ad3f874446adb1c51311bacec48d89 /Lib/test
parent5b8a6c5186be299d96dd483146dc6ea737ffdfe7 (diff)
downloadcpython-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.py13
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):