Skip to content

Commit 90de6a6

Browse files
committed
gh-117174: Rename <string> to <__interactive_string__> for interactive code objects
Using <string> leads to confusion when linecache it's populated with <string> entries as the inspect module heavily relies on it. An example: ./python -c "import inspect;x=eval('lambda x: x');print(inspect.getsource(x))" The code above should trigger an exception because we should not be able to get the source of x (it's dynamically generated) but if we use <string> as name for interactive code it will return gives the full string. Signed-off-by: Pablo Galindo <[email protected]>
1 parent 1dc1521 commit 90de6a6

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Rename ``<string>`` to ``<__interactive_string__>`` for interactive source
2+
lines to avoid unwanted collisions with other dynamically generated code.
3+
Patch by Pablo Galindo

Modules/main.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ pymain_run_command(wchar_t *command)
249249

250250
PyCompilerFlags cf = _PyCompilerFlags_INIT;
251251
cf.cf_flags |= PyCF_IGNORE_COOKIE;
252-
ret = _PyRun_SimpleStringFlagsWithName(PyBytes_AsString(bytes), "<string>", &cf);
252+
ret = _PyRun_SimpleStringFlagsWithName(PyBytes_AsString(bytes), "<__interactive_string__>", &cf);
253253
Py_DECREF(bytes);
254254
return (ret != 0);
255255

0 commit comments

Comments
 (0)