GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||
GeezerVison is showing github.com — gh-86298: Ensure that __loader__ and __spec__.loader agree in warnings.warn_explicit() by warsaw · Pull Request #97803 · python/cpython Conversation
|
|
Tagging @brettcannon |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Converting from draft since I now have tests. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
It's better to split these consistency fixes up into separate PRs, so this one only addresses the |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@brettcannon I think this branch is ready for review. It only changes the |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Note however that the semantics of the helper has changed, and can't be full on loader blessing... yet.
|
@brettcannon Please take another look. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Co-authored-by: Brett Cannon <[email protected]>
Co-authored-by: Brett Cannon <[email protected]>
Co-authored-by: Brett Cannon <[email protected]>
|
Status check is done, and it's a success ✅. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Sorry, I can't merge this PR. Reason: |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Status check is done, and it's a success ✅. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
* main: pythongh-86298: Ensure that __loader__ and __spec__.loader agree in warnings.warn_explicit() (pythonGH-97803) pythongh-82874: Convert remaining importlib format uses to f-str. (python#98005) Docs: Fix backtick errors found by sphinx-lint (python#97998) pythongh-97850: Remove deprecated functions from `importlib.utils` (python#97898) Remove extra spaces in custom openSSL documentation. (python#93568) pythonGH-90985: Revert "Deprecate passing a message into cancel()" (python#97999)
…arnings.warn_explicit() (pythonGH-97803) 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 # /tmp/foo.py import warnings import bar warnings.warn_explicit( 'warning!', RuntimeWarning, 'bar.py', 2, module='bar knee', module_globals=bar.__dict__, ) ``` ```python # /tmp/bar.py import sys import os import pathlib # __loader__ = pathlib.Path() ``` 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 ``` Automerge-Triggered-By: GH:warsaw
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.