https://github.com/DavidSpickett created https://github.com/llvm/llvm-project/pull/215271
Instead of importing it as reload_module. That name comes from https://reviews.llvm.org/D15209/ 7d2d09842a428bc0b45414ff0f32391a447e048d. reload_module is what the 2/3 compatibility library "six" called it. In Python 2 "reload" was a builtin and 3 moved it into importlib. We require 3.8 so we don't need to consider 2 anymore. >From f3794e3848778c0e4bec0d13b203e5548685e008 Mon Sep 17 00:00:00 2001 From: David Spickett <[email protected]> Date: Mon, 10 Aug 2026 13:01:39 +0000 Subject: [PATCH] [lldb] Use Python3's importlib.reload directly Instead of importing it as reload_module. That name comes from https://reviews.llvm.org/D15209/ 7d2d09842a428bc0b45414ff0f32391a447e048d. reload_module is what the 2/3 compatibility library "six" called it. In Python 2 "reload" was a builtin and 3 moved it into importlib. We require 3.8 so we don't need to consider 2 anymore. --- .../Python/ScriptInterpreterPython.cpp | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp index 8abdf41cb112e..872ab8758e822 100644 --- a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp +++ b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp @@ -770,17 +770,9 @@ ScriptInterpreterPythonImpl::ScriptInterpreterPythonImpl(Debugger &debugger) RunSimpleString(run_string.GetData()); run_string.Clear(); - run_string.Printf( - "run_one_line (%s, 'import copy, keyword, os, re, sys, uuid, lldb')", - m_dictionary_name.c_str()); - RunSimpleString(run_string.GetData()); - - // Reloading modules requires a different syntax in Python 2 and Python 3. - // This provides a consistent syntax no matter what version of Python. - run_string.Clear(); - run_string.Printf( - "run_one_line (%s, 'from importlib import reload as reload_module')", - m_dictionary_name.c_str()); + run_string.Printf("run_one_line (%s, 'import copy, keyword, os, re, sys, " + "uuid, lldb, importlib')", + m_dictionary_name.c_str()); RunSimpleString(run_string.GetData()); // WARNING: temporary code that loads Cocoa formatters - this should be done @@ -2635,10 +2627,10 @@ bool ScriptInterpreterPythonImpl::LoadScriptingModule( if (was_imported_globally || was_imported_locally) { if (!was_imported_locally) - command_stream.Printf("import %s ; reload_module(%s)", + command_stream.Printf("import %s ; importlib.reload(%s)", module_name.c_str(), module_name.c_str()); else - command_stream.Printf("reload_module(%s)", module_name.c_str()); + command_stream.Printf("importlib.reload(%s)", module_name.c_str()); } else command_stream.Printf("import %s", module_name.c_str()); _______________________________________________ lldb-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
