Skip to content

Commit c4b27d5

Browse files
committed
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`).
1 parent e65f8ea commit c4b27d5

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

python/extractor/imp.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,16 @@
1717
# Platform doesn't support dynamic loading.
1818
create_dynamic = None
1919

20-
from importlib._bootstrap import _ERR_MSG, _exec, _load, _builtin_from_name
20+
from importlib._bootstrap import _exec, _load, _builtin_from_name
2121
from importlib._bootstrap_external import SourcelessFileLoader
2222

23+
# In Python 3.14, `_ERR_MSG` was removed in favor of `_ERR_MSG_PREFIX`.
24+
try:
25+
from importlib._bootstrap import _ERR_MSG
26+
except ImportError:
27+
from importlib._bootstrap import _ERR_MSG_PREFIX
28+
_ERR_MSG = _ERR_MSG_PREFIX + '{name!r}'
29+
2330
from importlib import machinery
2431
from importlib import util
2532
import importlib

python/extractor/semmle/util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
#Semantic version of extractor.
1212
#Update this if any changes are made
13-
VERSION = "7.1.4"
13+
VERSION = "7.1.5"
1414

1515
PY_EXTENSIONS = ".py", ".pyw"
1616

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: fix
3+
---
4+
* The Python extractor no longer crashes with an `ImportError` when run using Python 3.14.

0 commit comments

Comments
 (0)