-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
gh-106233: Fix stacklevel in zoneinfo.InvalidTZPathWarning
#106234
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
ea9954f
gh-106233: Fix stacklevel in `zoneinfo.InvalidTZPathWarning`
sobolevn 5d4dc18
Merge branch 'main' into issue-106233
AlexWaygood 4ce9123
Use explicit `stacklevel` argument
sobolevn 7572618
Merge branch 'main' into issue-106233
sobolevn 303255f
Add test
sobolevn ccdbaa6
Better use `__file__`
sobolevn 0a2800e
Address review
sobolevn 2f9dbf4
Address review
sobolevn 62b1fb2
Address review
sobolevn 0ab22a4
Address review
sobolevn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Add test
- Loading branch information
commit 303255f685bce97f210a1436aaa40269b0682b70
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -14,13 +14,14 @@ | |||||||||||
import struct | ||||||||||||
import tempfile | ||||||||||||
import unittest | ||||||||||||
import warnings | ||||||||||||
from datetime import date, datetime, time, timedelta, timezone | ||||||||||||
from functools import cached_property | ||||||||||||
|
||||||||||||
from test.support import MISSING_C_DOCSTRINGS | ||||||||||||
from test.test_zoneinfo import _support as test_support | ||||||||||||
from test.test_zoneinfo._support import OS_ENV_LOCK, TZPATH_TEST_LOCK, ZoneInfoTestBase | ||||||||||||
from test.support.import_helper import import_module | ||||||||||||
from test.support.import_helper import import_module, CleanImport | ||||||||||||
|
||||||||||||
lzma = import_module('lzma') | ||||||||||||
py_zoneinfo, c_zoneinfo = test_support.get_modules() | ||||||||||||
|
@@ -1717,11 +1718,31 @@ def test_env_variable_relative_paths(self): | |||||||||||
for input_paths, expected_paths in test_cases: | ||||||||||||
path_var = os.pathsep.join(input_paths) | ||||||||||||
with self.python_tzpath_context(path_var): | ||||||||||||
with self.subTest("module-level warning", path_var=path_var): | ||||||||||||
with CleanImport("zoneinfo", "zoneinfo._tzpath"): | ||||||||||||
with warnings.catch_warnings(record=True) as wlog: | ||||||||||||
import zoneinfo | ||||||||||||
self.assertEqual(len(wlog), 1) | ||||||||||||
# Since we use import hacks, we cannot just use `isinstance` | ||||||||||||
self.assertEqual( | ||||||||||||
type(wlog[0].message).__qualname__, | ||||||||||||
"InvalidTZPathWarning", | ||||||||||||
) | ||||||||||||
# It should represent the current file: | ||||||||||||
self.assertTrue( | ||||||||||||
wlog[0].filename.endswith("test_zoneinfo.py"), | ||||||||||||
msg=wlog[0].filename, | ||||||||||||
) | ||||||||||||
|
||||||||||||
with self.subTest("warning", path_var=path_var): | ||||||||||||
# Note: Per PEP 615 the warning is implementation-defined | ||||||||||||
# behavior, other implementations need not warn. | ||||||||||||
with self.assertWarns(self.module.InvalidTZPathWarning): | ||||||||||||
with self.assertWarns(self.module.InvalidTZPathWarning) as w: | ||||||||||||
self.module.reset_tzpath() | ||||||||||||
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 commentThe reason will be displayed to describe this comment to others. Learn more. Why not simply:
Suggested change
? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've already done that in ccdbaa6 :) |
||||||||||||
|
||||||||||||
tzpath = self.module.TZPATH | ||||||||||||
with self.subTest("filtered", path_var=path_var): | ||||||||||||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.