-
-
Notifications
You must be signed in to change notification settings - Fork 30.5k
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
gh-86298: Ensure that __loader__ and __spec__.loader agree in warnings.warn_explicit() #97803
Merged
Commits on Oct 3, 2022
-
PoC for checking both __loader__ and __spec__.loader
In _warnings.c, in the C equivalent of warnings.warn_explicit(), if the module globals are given (and not None), the warning will attempt to get the source line for the issued warning. To do this, it needs the module's loader. Previously, it would only look up `__loader__` in the module globals. In python#86298 we want to defer to the `__spec__.loader` if available. The first step on this journey is to check that `loader` == `__spec__.loader` and issue another warning if it is not. This commit does that. Since this is a PoC, only manual testing for now. ```python import warnings import bar warnings.warn_explicit( 'warning!', RuntimeWarning, 'bar.py', 2, module='bar knee', module_globals=bar.__dict__, ) ``` ```python import sys import os import pathlib ``` Then running this: `./python.exe -Wdefault /tmp/foo.py` Produces: ``` bar.py:2: RuntimeWarning: warning! import os ``` Uncomment the `__loader__ = ` line in `bar.py` and try it again: ``` sys:1: ImportWarning: Module bar; __loader__ != __spec__.loader (<_frozen_importlib_external.SourceFileLoader object at 0x109f7dfa0> != PosixPath('.')) bar.py:2: RuntimeWarning: warning! import os ```
Configuration menu - View commit details
-
Copy full SHA for 37b581a - Browse repository at this point
Copy the full SHA 37b581aView commit details -
Configuration menu - View commit details
-
Copy full SHA for 049910b - Browse repository at this point
Copy the full SHA 049910bView commit details
Commits on Oct 4, 2022
-
Configuration menu - View commit details
-
Copy full SHA for 317e253 - Browse repository at this point
Copy the full SHA 317e253View commit details -
Configuration menu - View commit details
-
Copy full SHA for 428d863 - Browse repository at this point
Copy the full SHA 428d863View commit details -
Configuration menu - View commit details
-
Copy full SHA for 06d686d - Browse repository at this point
Copy the full SHA 06d686dView commit details -
Configuration menu - View commit details
-
Copy full SHA for fc50fe1 - Browse repository at this point
Copy the full SHA fc50fe1View commit details
Commits on Oct 6, 2022
-
Configuration menu - View commit details
-
Copy full SHA for 1066b9f - Browse repository at this point
Copy the full SHA 1066b9fView commit details -
Configuration menu - View commit details
-
Copy full SHA for 4602366 - Browse repository at this point
Copy the full SHA 4602366View commit details -
Note however that the semantics of the helper has changed, and can't be full on loader blessing... yet.
Configuration menu - View commit details
-
Copy full SHA for 831f832 - Browse repository at this point
Copy the full SHA 831f832View commit details -
Configuration menu - View commit details
-
Copy full SHA for 37254cf - Browse repository at this point
Copy the full SHA 37254cfView commit details -
Configuration menu - View commit details
-
Copy full SHA for fe9d62e - Browse repository at this point
Copy the full SHA fe9d62eView commit details -
Configuration menu - View commit details
-
Copy full SHA for 3bcdba9 - Browse repository at this point
Copy the full SHA 3bcdba9View commit details
Commits on Oct 7, 2022
-
Configuration menu - View commit details
-
Copy full SHA for f5cef9c - Browse repository at this point
Copy the full SHA f5cef9cView commit details -
Update Lib/importlib/_bootstrap_external.py
Co-authored-by: Brett Cannon <[email protected]>
Configuration menu - View commit details
-
Copy full SHA for 5600c9c - Browse repository at this point
Copy the full SHA 5600c9cView commit details -
Update Lib/test/test_importlib/import_/test_helpers.py
Co-authored-by: Brett Cannon <[email protected]>
Configuration menu - View commit details
-
Copy full SHA for 8631e53 - Browse repository at this point
Copy the full SHA 8631e53View commit details -
Update Lib/test/test_importlib/import_/test_helpers.py
Co-authored-by: Brett Cannon <[email protected]>
Configuration menu - View commit details
-
Copy full SHA for b1b0d86 - Browse repository at this point
Copy the full SHA b1b0d86View commit details -
Configuration menu - View commit details
-
Copy full SHA for 823400c - Browse repository at this point
Copy the full SHA 823400cView commit details
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.