Python: Fix ImportError in imp.py under Python 3.14#20630
Merged
Conversation
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`).
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR fixes a Python 3.14 compatibility issue where the extractor crashes with an ImportError due to the removal of _ERR_MSG from Python's importlib._bootstrap module. The fix implements a fallback mechanism that constructs the error message format when the original import fails.
- Adds compatibility handling for the removed
_ERR_MSGconstant in Python 3.14 - Updates the extractor version to reflect the fix
- Documents the change in the changelog
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
python/extractor/imp.py |
Implements try/except fallback to construct _ERR_MSG when not available in Python 3.14+ |
python/extractor/semmle/util.py |
Bumps extractor version from 7.1.4 to 7.1.5 |
python/ql/lib/change-notes/2025-10-13-fix-importerror-on-python-3.14.md |
Documents the Python 3.14 compatibility fix |
akoeplinger
added a commit
to akoeplinger/codeql
that referenced
this pull request
Nov 25, 2025
Follow-up to github#20630 The fix didn't fully work since when we raise the ImportError in `find_module` we don't pass a named argument into the format string which causes a `KeyError`. We need to use a format string without named arguments, like Python 3.13 and earlier did.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
It seems
_ERR_MSGwas silently removed in Python 3.14, leading to anImportErrorwhen running the extractor.To fix this, we explicitly set
_ERR_MSGwhen the existing import fails (using_ERR_MSG_PREFIXwhich is available in Python 3.14+, along with the bits that make up the difference between this and_ERR_MSG).