Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
gh-114763: Protect lazy loading modules from attribute access race#114781
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes from1 commit
Commits
Show all changes
12 commits Select commitHold shift + click to select a range
d57f4eb gh-114763: Protect lazy loading modules from attribute access race
effigies3db717c TEST: Reproduce gh-114763
effigies5424d0c Add new blurb
effigies96c08c5 Improve comments around the branching
effigies3642ddc TEST: Use TestCase.assert* methods
effigies46238e5 Merge branch 'main' into fix-issue-114763
brettcannon6accf0c Apply suggestions from code review
effigiesbb2292f TEST: Require working threading for test_module_load_race
effigies57fe084 Move threading import to module level of importlib.util
effigies40383a0 Make is_loading a bool instead of Event
effigies6322dd6 Merge branch 'main' into fix-issue-114763
effigies023d65d Merge branch 'main' into fix-issue-114763
brettcannonFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
Apply suggestions from code review
Co-authored-by: Brett Cannon <brett@python.org>
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
commit6accf0c07546fbb65559384b3140b91c52c621be
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -182,13 +182,13 @@ def __getattribute__(self, attr): | ||
| # exec_module(), which will access module.__dict__, module.__name__, | ||
| # and/or module.__spec__, reentering this method. These accesses | ||
| # need to be allowed to proceed without triggering the load again. | ||
| if loader_state['is_loading'].is_set() and attr.startswith('__') and attr.endswith('__'): | ||
| return object.__getattribute__(self, attr) | ||
| loader_state['is_loading'].set() | ||
effigies marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| __dict__ = object.__getattribute__(self, '__dict__') | ||
| # All module metadata must begathered from __spec__ in order to avoid | ||
| # using mutated values. | ||
| # Get the original name to make sure no object substitution occurred | ||
| # in sys.modules. | ||
| @@ -199,7 +199,7 @@ def __getattribute__(self, attr): | ||
| attrs_now = __dict__ | ||
| attrs_updated = {} | ||
| for key, value in attrs_now.items(): | ||
| # Code that setan attribute may have kept a reference to the | ||
| # assigned object, making identity more important than equality. | ||
| if key not in attrs_then: | ||
| attrs_updated[key] = value | ||
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.