| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent d7df781 commit 954b2cf
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1061,8 +1061,24 @@ def four_freevars(): | |||
| 1061 | 1061 | three_freevars.__code__, | |
| 1062 | 1062 | three_freevars.__globals__, | |
| 1063 | 1063 | closure=my_closure) | |
| 1064 | + my_closure = tuple(my_closure) | ||
| 1065 | + | ||
| 1066 | + # should fail: anything passed to closure= isn't allowed | ||
| 1067 | + # when the source is a string | ||
| 1068 | + self.assertRaises(TypeError, | ||
| 1069 | + exec, | ||
| 1070 | + "pass", | ||
| 1071 | + closure=int) | ||
| 1072 | + | ||
| 1073 | + # should fail: correct closure= argument isn't allowed | ||
| 1074 | + # when the source is a string | ||
| 1075 | + self.assertRaises(TypeError, | ||
| 1076 | + exec, | ||
| 1077 | + "pass", | ||
| 1078 | + closure=my_closure) | ||
| 1064 | 1079 | ||
| 1065 | 1080 | # should fail: closure tuple with one non-cell-var | |
| 1081 | + my_closure = list(my_closure) | ||
| 1066 | 1082 | my_closure[0] = int | |
| 1067 | 1083 | my_closure = tuple(my_closure) | |
| 1068 | 1084 | self.assertRaises(TypeError, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1 @@ | |||
| 1 | + Fixed an assertion error for :func:`exec` passed a string ``source`` and a non-``None`` ``closure``. Patch by Bartosz Sławecki. | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1169,6 +1169,7 @@ builtin_exec_impl(PyObject *module, PyObject *source, PyObject *globals, | |||
| 1169 | 1169 | if (closure != NULL) { | |
| 1170 | 1170 | PyErr_SetString(PyExc_TypeError, | |
| 1171 | 1171 | "closure can only be used when source is a code object"); | |
| 1172 | + goto error; | ||
| 1172 | 1173 | } | |
| 1173 | 1174 | PyObject *source_copy; | |
| 1174 | 1175 | const char *str; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments