8000 gh-110805: Allow the repl to show source code and complete tracebacks by pablogsal · Pull Request #110775 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-110805: Allow the repl to show source code and complete tracebacks #110775

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Oct 13, 2023
Prev Previous commit
Next Next commit
fixup! fixup! fixup! fixup! fixup! Allow the repl to show source code…
… and complete tracebacks
  • Loading branch information
pablogsal committed Oct 13, 2023
commit 2da72a3dcd41e51baab354351d8055d46a310b8e
20 changes: 14 additions & 6 deletions Python/pythonrun.c
Original file line number Diff line number Diff line change
Expand Up @@ -1295,13 +1295,22 @@ run_mod(mod_ty mod, PyObject *filename, PyObject *globals, PyObject *locals,

PyObject *print_tb_func = PyObject_GetAttrString(linecache_module, "_register_code");

if (print_tb_func == NULL || !PyCallable_Check(print_tb_func)) {
if (print_tb_func == NULL) {
Py_DECREF(co);
Py_DECREF(interactive_filename);
Py_DECREF(linecache_module);
return NULL;
}

if (!PyCallable_Check(print_tb_func)) {
Py_DECREF(co);
Py_DECREF(interactive_filename);
Py_DECREF(linecache_module);
Py_DECREF(print_tb_func);
PyErr_SetString(PyExc_ValueError, "linecache._register_code is not callable");
return NULL;
}

PyObject* result = PyObject_CallFunction(
print_tb_func, "OOO",
interactive_filename,
Expand All @@ -1311,14 +1320,13 @@ run_mod(mod_ty mod, PyObject *filename, PyObject *globals, PyObject *locals,

Py_DECREF(interactive_filename);

Py_DECREF(linecache_module);
Py_XDECREF(print_tb_func);
Py_XDECREF(result);
if (!result) {
Py_DECREF(linecache_module);
Py_XDECREF(print_tb_func);
Py_DECREF(co);
return NULL;
}
Py_DECREF(linecache_module);
Py_XDECREF(print_tb_func);
Py_DECREF(result);
}

if (_PySys_Audit(tstate, "exec", "O", co) < 0) {
Expand Down
0