-
-
Notifications
You must be signed in to change notification settings - Fork 30.7k
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-119049: Fix incorrect usage of GET_WARNINGS_ATTR
#119063
Conversation
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.
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?
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.
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.
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 yet been imported. (cherry picked from commit 100c7ab) 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 the 3.13 branch. |
@serhiy-storchaka I'm trying to do backport to the 3.12 branch manually, and realize that this cannot be done without the backport of e1d8c65. |
Is it because of passing the code via the |
GH-119119 is a backport of this pull request to the 3.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 yet been imported.
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