Skip to content

Commit

Permalink
Clear the error buffer before redirecting stderr.
Browse files Browse the repository at this point in the history
I just noticed this bug if the env doesn't have jedi installed.
  • Loading branch information
cindytsai committed Aug 26, 2024
1 parent 9bac05b commit 0263539
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/libyt_python_shell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -469,8 +469,12 @@ CodeValidity LibytPythonShell::check_code_validity(const std::string& code, bool

CodeValidity code_validity;

PyRun_SimpleString("import sys, io\n");
PyRun_SimpleString("sys.OUTPUT_STDERR=''\nstderr_buf=io.StringIO()\nsys.stderr=stderr_buf\n");
// clear error buffer before redirecting stderr
PyErr_Clear();
PyRun_SimpleString("import sys, io");
PyRun_SimpleString("sys.OUTPUT_STDERR=''");
PyRun_SimpleString("stderr_buf=io.StringIO()");
PyRun_SimpleString("sys.stderr=stderr_buf");

PyObject* py_test_compile;
if (prompt_env) {
Expand Down

0 comments on commit 0263539

Please sign in to comment.