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-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.
serhiy-storchaka left a comment
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.
serhiy-storchaka left a comment
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? |
serhiy-storchaka commentedMay 16, 2024
How difficult is to write a test for this case? |
Eclips4 commentedMay 16, 2024
It's not difficult. |
serhiy-storchaka left a comment
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>
serhiy-storchaka left a comment
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.
serhiy-storchaka commentedMay 16, 2024
A NEWS entry is needed since this is a user visible change. |
Eclips4 commentedMay 16, 2024
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. |
serhiy-storchaka commentedMay 17, 2024
Is it because of passing the code via the |
GH-119119 is a backport of this pull request to the3.12 branch. |
Eclips4 commentedMay 17, 2024
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_ATTRis trying to get theATTRattribute of the Pythonwarningsmodule. If the third parameter is true, it tries to import thewarningsmodule if it hasn't been imported already.All of the calls to
call_show_warningare made with thesource = NULLargument, 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
warningsmodule if it has not already imported, which leads us to the issue described in the#119049.This is why
test_io.test_check_encoding_warningworks whenimport warningsis used inpathlib._local.pyand fails when we remove this statement.import warningsin pathlib #119049