-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
gh-123880: Allow recursive import of single-phase-init modules #123950
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
1700e33
gh-123880: Allow recursive import of single-phase-init modules
encukou 484678f
Add regression test
encukou 78852fa
Add a blurb
encukou 173f06c
Apply suggestions from code review
encukou 48a6c1d
Record the intentional static global
encukou a1da713
Apply typo fixes from code review
encukou 16dc155
Use more shared helpers
encukou 5fc359b
Merge in the main branch
encukou c67517d
Add @requires_singlephase_init decorator
encukou de9840c
Skip if _testsinglephase is not available
encukou c7392f7
Also use the test helper for the Python helper module
encukou aa825d2
Merge in the main branch
encukou 72cd269
Merge branch 'main' into spi-cache
encukou File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
"""Cilcular import involving a single-phase-init extension. | ||
encukou marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
This module is imported from the _testsinglephase_circular module from | ||
_testsinglephase, and imports that module again. | ||
""" | ||
|
||
import importlib | ||
import _testsinglephase | ||
|
||
name = '_testsinglephase_circular' | ||
filename = _testsinglephase.__file__ | ||
loader = importlib.machinery.ExtensionFileLoader(name, filename) | ||
spec = importlib.util.spec_from_file_location(name, filename, loader=loader) | ||
mod = importlib._bootstrap._load(spec) |
2 changes: 2 additions & 0 deletions
2
Misc/NEWS.d/next/C_API/2024-09-12-16-16-24.gh-issue-123880.2-8vcj.rst
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Fixed a bug that prevented circular imports of extension modules that use | ||
single-phase initialization. |
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
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know if I love using this API for the test since it's somewhat of a hack to start, but I also understand not wanting to paste in 2 more lines of boilerplate to get the module created and set
sys.modules
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was done elsewhere in the file too; I merged the usage into a common helper. If it breaks, there's now just one place to change.
(We never got around to adding proper public API for multiple modules in one shared library, but then, it's really only useful for testing import mechanism...)
In this case I slightly prefer not to touch
sys.modules
here -- the “inner” import should do that.