-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
gh-106233: Fix stacklevel in zoneinfo.InvalidTZPathWarning
#106234
8000 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
Conversation
@sobolevn, could you address @serhiy-storchaka's comments from the linked issue? #106233 (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.
What happens when call `zoneinfo.reset_tzpath() (which is the part of the API) directly in your code?
Could you please add tests?
Yes, these two calls have two different stacklevels :(
I can overly-complicate this function by passing the stacklevel as an argument, when calling it on a module level, but is it worth it? Something like: TZPATH = ()
reset_tzpath(module_level=True) |
The simplest way to solve this -- introduce |
Prep: Before:
Now it produces:
Note that two warnings are glued together, because they are identical. |
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.
Please add tests.
self.assertTrue( | ||
w.warnings[0].filename.endswith("test_zoneinfo.py"), | ||
msg=w.warnings[0].filename, | ||
) |
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.
Why not simply:
self.assertTrue( | |
w.warnings[0].filename.endswith("test_zoneinfo.py"), | |
msg=w.warnings[0].filename, | |
) | |
self.assertEqual(w.warnings[0].filename, __file__) |
?
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.
I've already done that in ccdbaa6 :)
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.
And subTest() is no longer needed.
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.
Thank you for your PR @sobolevn. Does it need backporting? |
Thanks @sobolevn for the PR, and @serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 3.12. |
…honGH-106234) (cherry picked from commit d7334e2) Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
GH-115081 is a backport of this pull request to the 3.12 branch. |
|
Yes, I think that this is a bugfix that should be backported. Thanks a lot for your patience :)
It is unrelated. |
Given:
Now the warning looks like this:
InvalidTZPathWarning
warning with a stacklevel #106233