From c4b27d5f281697ca033a2aa4a20e84db1eeabd98 Mon Sep 17 00:00:00 2001 From: Taus Date: Mon, 13 Oct 2025 13:50:43 +0000 Subject: [PATCH] Python: Fix `ImportError` in `imp.py` under Python 3.14 It seems `_ERR_MSG` was silently removed in Python 3.14, leading to an `ImportError` when running the extractor. To fix this, we explicitly set `_ERR_MSG` when the existing import fails (using `_ERR_MSG_PREFIX` which is available in Python 3.14+, along with the bits that make up the difference between this and `_ERR_MSG`). --- python/extractor/imp.py | 9 ++++++++- python/extractor/semmle/util.py | 2 +- .../2025-10-13-fix-importerror-on-python-3.14.md | 4 ++++ 3 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 python/ql/lib/change-notes/2025-10-13-fix-importerror-on-python-3.14.md diff --git a/python/extractor/imp.py b/python/extractor/imp.py index 6a0685559fd1..8d703250b671 100644 --- a/python/extractor/imp.py +++ b/python/extractor/imp.py @@ -17,9 +17,16 @@ # Platform doesn't support dynamic loading. create_dynamic = None -from importlib._bootstrap import _ERR_MSG, _exec, _load, _builtin_from_name +from importlib._bootstrap import _exec, _load, _builtin_from_name from importlib._bootstrap_external import SourcelessFileLoader +# In Python 3.14, `_ERR_MSG` was removed in favor of `_ERR_MSG_PREFIX`. +try: + from importlib._bootstrap import _ERR_MSG +except ImportError: + from importlib._bootstrap import _ERR_MSG_PREFIX + _ERR_MSG = _ERR_MSG_PREFIX + '{name!r}' + from importlib import machinery from importlib import util import importlib diff --git a/python/extractor/semmle/util.py b/python/extractor/semmle/util.py index 8196f76e4375..2f6a18ac7a97 100644 --- a/python/extractor/semmle/util.py +++ b/python/extractor/semmle/util.py @@ -10,7 +10,7 @@ #Semantic version of extractor. #Update this if any changes are made -VERSION = "7.1.4" +VERSION = "7.1.5" PY_EXTENSIONS = ".py", ".pyw" diff --git a/python/ql/lib/change-notes/2025-10-13-fix-importerror-on-python-3.14.md b/python/ql/lib/change-notes/2025-10-13-fix-importerror-on-python-3.14.md new file mode 100644 index 000000000000..d2eefde0e119 --- /dev/null +++ b/python/ql/lib/change-notes/2025-10-13-fix-importerror-on-python-3.14.md @@ -0,0 +1,4 @@ +--- +category: fix +--- +* The Python extractor no longer crashes with an `ImportError` when run using Python 3.14.