gh-106233: Fix stacklevel in zoneinfo.InvalidTZPathWarning#106234
gh-106233: Fix stacklevel in zoneinfo.InvalidTZPathWarning#106234serhiy-storchaka merged 10 commits intopython:mainfrom
zoneinfo.InvalidTZPathWarning#106234Conversation
|
@sobolevn, could you address @serhiy-storchaka's comments from the linked issue? #106233 (comment) |
serhiy-storchaka
left a comment
There was a problem hiding this comment.
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.
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__) |
?
serhiy-storchaka
left a comment
There was a problem hiding this comment.
And subTest() is no longer needed.
|
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:
InvalidTZPathWarningwarning with a stacklevel #106233