Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32.4k
gh-119049: Fix incorrect usage ofGET_WARNINGS_ATTR
#119063
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
Uh oh!
There was an error while loading.Please reload this page.
Conversation
Uh oh!
There was an error while loading.Please reload this page.
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.
LGTM.
Uh oh!
There was an error while loading.Please reload this page.
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.
On other hand, what happens when it is called at the late stage of Python shutdown, when import does not work? Does it emit any warning or raise an exception?
Eclips4 commentedMay 15, 2024 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
No, it's just omit the source in the warning. Should we emit warning or raise a exception? |
How difficult is to write a test for this case? |
It's not difficult. |
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.
Thank you for the new test. Even if its result was not affected by this change, it is nice to check this.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
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.
LGTM.
Uh oh!
There was an error while loading.Please reload this page.
A NEWS entry is needed since this is a user visible change. |
Thanks for the review, Serhiy. |
Thanks@Eclips4 for the PR, and@serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 3.12, 3.13. |
…d by C API (pythonGH-119063)The source line was not displayed if the warnings module had not yetbeen imported.(cherry picked from commit100c7ab)Co-authored-by: Kirill Podoprigora <kirill.bast9@mail.ru>
Sorry,@Eclips4 and@serhiy-storchaka, I could not cleanly backport this to
|
GH-119106 is a backport of this pull request to the3.13 branch. |
Eclips4 commentedMay 17, 2024 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
@serhiy-storchaka I'm trying to do backport to the 3.12 branch manually, and realize that this cannot be done without the backport ofe1d8c65. |
Is it because of passing the code via the |
GH-119119 is a backport of this pull request to the3.12 branch. |
Yes, you're right! Thanks for the hint. Check please the#119119. |
…d by C API (pythonGH-119063)The source line was not displayed if the warnings module had not yetbeen imported.
Uh oh!
There was an error while loading.Please reload this page.
GET_WARNINGS_ATTR
is trying to get theATTR
attribute of the Pythonwarnings
module. If the third parameter is true, it tries to import thewarnings
module if it hasn't been imported already.All of the calls to
call_show_warning
are made with thesource = NULL
argument, so this statementshow_fn = GET_WARNINGS_ATTR(interp, _showwarnmsg, source != NULL);
always becomesshow_fn = GET_WARNINGS_ATTR(interp, _showwarnmsg, 0);
.So it never triess to import the
warnings
module if it has not already imported, which leads us to the issue described in the#119049.This is why
test_io.test_check_encoding_warning
works whenimport warnings
is used inpathlib._local.py
and fails when we remove this statement.import warnings
in pathlib #119049