From 02635398719e8013e58688f68fda828923df9494 Mon Sep 17 00:00:00 2001 From: cindytsai Date: Mon, 26 Aug 2024 12:20:57 -0500 Subject: [PATCH] Clear the error buffer before redirecting stderr. I just noticed this bug if the env doesn't have jedi installed. --- src/libyt_python_shell.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/libyt_python_shell.cpp b/src/libyt_python_shell.cpp index d3ed426b..d5e03e74 100644 --- a/src/libyt_python_shell.cpp +++ b/src/libyt_python_shell.cpp @@ -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) {