Skip to content

Commit 2f30324

Browse files
committed
attempt to fix issue with incorrect reporting of source code from PYTHON_BASIC_REPL
1 parent 3000594 commit 2f30324

1 file changed

Lines changed: 21 additions & 2 deletions

File tree

Python/pythonrun.c

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1365,6 +1365,25 @@ run_eval_code_obj(PyThreadState *tstate, PyCodeObject *co, PyObject *globals, Py
13651365
return PyEval_EvalCode((PyObject*)co, globals, locals);
13661366
}
13671367

1368+
PyObject *
1369+
get_interactive_filename(PyObject *filename, Py_ssize_t count){
1370+
PyObject *result;
1371+
Py_ssize_t len = PyUnicode_GET_LENGTH(filename);
1372+
1373+
if (len >= 2
1374+
&& PyUnicode_ReadChar(filename, 0) == '<'
1375+
&& PyUnicode_ReadChar(filename, len - 1) == '>') {
1376+
PyObject *middle = PyUnicode_Substring(filename, 1, len-1);
1377+
result = PyUnicode_FromFormat("<%U-%d>", middle, count);
1378+
Py_DECREF(middle);
1379+
} else {
1380+
result = PyUnicode_FromFormat(
1381+
"%U-%d", filename, count);
1382+
}
1383+
return result;
1384+
1385+
}
1386+
13681387
static PyObject *
13691388
run_mod(mod_ty mod, PyObject *filename, PyObject *globals, PyObject *locals,
13701389
PyCompilerFlags *flags, PyArena *arena, PyObject* interactive_src,
@@ -1375,8 +1394,8 @@ run_mod(mod_ty mod, PyObject *filename, PyObject *globals, PyObject *locals,
13751394
if (interactive_src) {
13761395
PyInterpreterState *interp = tstate->interp;
13771396
if (generate_new_source) {
1378-
interactive_filename = PyUnicode_FromFormat(
1379-
"%U-%d", filename, interp->_interactive_src_count++);
1397+
interactive_filename = get_interactive_filename(
1398+
filename, interp->_interactive_src_count++);
13801399
} else {
13811400
Py_INCREF(interactive_filename);
13821401
}

0 commit comments

Comments
 (0)