mirror of
https://github.com/python/cpython.git
synced 2025-08-03 00:23:06 +00:00
[3.13] gh-130070: Fix exec(<string>, closure=<non-None>)
unexpected path (GH-130071) (#132627)
gh-130070: Fix `exec(<string>, closure=<non-None>)` unexpected path (#130071)
Fixed an assertion error (so, it could be reproduced only in builds with assertions enabled)
for `exec` when the `source` argument is a string and the `closure` argument is not `None`.
Co-authored-by: sobolevn <mail@sobolevn.me>
(cherry picked from commit 954b2cf031
)
This commit is contained in:
parent
db7ad1c89f
commit
582d1ef463
3 changed files with 18 additions and 0 deletions
|
@ -974,8 +974,24 @@ class BuiltinTest(unittest.TestCase):
|
|||
three_freevars.__code__,
|
||||
three_freevars.__globals__,
|
||||
closure=my_closure)
|
||||
my_closure = tuple(my_closure)
|
||||
|
||||
# should fail: anything passed to closure= isn't allowed
|
||||
# when the source is a string
|
||||
self.assertRaises(TypeError,
|
||||
exec,
|
||||
"pass",
|
||||
closure=int)
|
||||
|
||||
# should fail: correct closure= argument isn't allowed
|
||||
# when the source is a string
|
||||
self.assertRaises(TypeError,
|
||||
exec,
|
||||
"pass",
|
||||
closure=my_closure)
|
||||
|
||||
# should fail: closure tuple with one non-cell-var
|
||||
my_closure = list(my_closure)
|
||||
my_closure[0] = int
|
||||
my_closure = tuple(my_closure)
|
||||
self.assertRaises(TypeError,
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
Fixed an assertion error for :func:`exec` passed a string ``source`` and a non-``None`` ``closure``. Patch by Bartosz Sławecki.
|
|
@ -1154,6 +1154,7 @@ builtin_exec_impl(PyObject *module, PyObject *source, PyObject *globals,
|
|||
if (closure != NULL) {
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"closure can only be used when source is a code object");
|
||||
goto error;
|
||||
}
|
||||
PyObject *source_copy;
|
||||
const char *str;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue