mirror of
https://github.com/python/cpython.git
synced 2025-10-20 08:23:47 +00:00
[3.13] gh-137576: Fix for Basic REPL showing incorrect code in tracebacks with PYTHONSTARTUP
(GH-137625) (#137778)
(cherry picked from commit 04f8ef663b
)
Co-authored-by: Kirill Podoprigora <kirill.bast9@mail.ru>
This commit is contained in:
parent
785b396719
commit
5131b8fe7e
4 changed files with 90 additions and 3 deletions
|
@ -1385,6 +1385,29 @@ run_eval_code_obj(PyThreadState *tstate, PyCodeObject *co, PyObject *globals, Py
|
|||
return v;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
get_interactive_filename(PyObject *filename, Py_ssize_t count)
|
||||
{
|
||||
PyObject *result;
|
||||
Py_ssize_t len = PyUnicode_GET_LENGTH(filename);
|
||||
|
||||
if (len >= 2
|
||||
&& PyUnicode_ReadChar(filename, 0) == '<'
|
||||
&& PyUnicode_ReadChar(filename, len - 1) == '>') {
|
||||
PyObject *middle = PyUnicode_Substring(filename, 1, len-1);
|
||||
if (middle == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
result = PyUnicode_FromFormat("<%U-%d>", middle, count);
|
||||
Py_DECREF(middle);
|
||||
} else {
|
||||
result = PyUnicode_FromFormat(
|
||||
"%U-%d", filename, count);
|
||||
}
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
run_mod(mod_ty mod, PyObject *filename, PyObject *globals, PyObject *locals,
|
||||
PyCompilerFlags *flags, PyArena *arena, PyObject* interactive_src,
|
||||
|
@ -1395,8 +1418,8 @@ run_mod(mod_ty mod, PyObject *filename, PyObject *globals, PyObject *locals,
|
|||
if (interactive_src) {
|
||||
PyInterpreterState *interp = tstate->interp;
|
||||
if (generate_new_source) {
|
||||
interactive_filename = PyUnicode_FromFormat(
|
||||
"%U-%d", filename, interp->_interactive_src_count++);
|
||||
interactive_filename = get_interactive_filename(
|
||||
filename, interp->_interactive_src_count++);
|
||||
} else {
|
||||
Py_INCREF(interactive_filename);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue