From ba1296e86899c7433dabfea479f970cb5c28593e Mon Sep 17 00:00:00 2001 From: Gabriel Studer <gabriel.studer@unibas.ch> Date: Tue, 23 Aug 2022 10:36:29 +0200 Subject: [PATCH] don't use deprecated parser module Python interpreter in DNG uses the parser module to identify simple one line expressions. That module is gone in Python 3.10. Functionality gets replaced by the builtin compile function. --- .../src/python_shell/python_interpreter_worker.cc | 15 +++------------ .../src/python_shell/python_interpreter_worker.hh | 1 - 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/modules/gui/src/python_shell/python_interpreter_worker.cc b/modules/gui/src/python_shell/python_interpreter_worker.cc index 272f018a4..1a0d3bab8 100644 --- a/modules/gui/src/python_shell/python_interpreter_worker.cc +++ b/modules/gui/src/python_shell/python_interpreter_worker.cc @@ -21,6 +21,7 @@ #include "python_interpreter_worker.hh" #include "python_interpreter.hh" + namespace ost { namespace gui { namespace { @@ -55,7 +56,7 @@ PythonInterpreterWorker::PythonInterpreterWorker(): current_id_(), awake_(false) { - parse_expr_cmd_=bp::import("parser").attr("expr"); + parse_expr_cmd_=bp::import("__main__").attr("__builtins__").attr("compile"); main_namespace_ = bp::extract<bp::dict>(bp::import("__main__").attr("__dict__")); repr_=bp::import("__main__").attr("__builtins__").attr("repr"); #ifndef _MSC_VER @@ -98,16 +99,6 @@ unsigned int PythonInterpreterWorker::AddCommand(const QString& command) return command_id_; } -bool PythonInterpreterWorker::is_simple_expression_(const QString& expr) -{ - try { - parse_expr_cmd_(bp::str(expr.toStdString())); - return true; - } catch(bp::error_already_set&) { - PyErr_Clear(); - return false; - } -} void PythonInterpreterWorker::run_command_(std::pair<unsigned int,QString> pair) { #ifndef _MSC_VER @@ -148,7 +139,7 @@ void PythonInterpreterWorker::run_command_(std::pair<unsigned int,QString> pair) bool PythonInterpreterWorker::is_simple_expression(const QString& expr) { try { - parse_expr_cmd_(bp::str(expr.toStdString())); + parse_expr_cmd_(bp::str(expr.toStdString()), "<string>", "eval"); return true; } catch(bp::error_already_set&) { PyErr_Clear(); diff --git a/modules/gui/src/python_shell/python_interpreter_worker.hh b/modules/gui/src/python_shell/python_interpreter_worker.hh index c8dc4ba3f..0fcb45614 100644 --- a/modules/gui/src/python_shell/python_interpreter_worker.hh +++ b/modules/gui/src/python_shell/python_interpreter_worker.hh @@ -62,7 +62,6 @@ protected slots: protected: bool is_simple_expression(const QString& expr); void run_command_(std::pair<unsigned int,QString> pair); - bool is_simple_expression_(const QString& expr); QQueue<std::pair<unsigned int,QString> > exec_queue_; unsigned int command_id_; boost::shared_ptr<OutputRedirector> output_redirector_; -- GitLab