Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 95dcf3e

Browse files
committed
gh-96463: fix load_tzdata raising OSError, not ZoneInfoNotFoundError
1 parent 858cb79 commit 95dcf3e

File tree

3 files changed

+6
-1
lines changed

3 files changed

+6
-1
lines changed

Lib/test/test_zoneinfo/test_zoneinfo.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ def test_bad_keys(self):
220220
"America.Los_Angeles",
221221
"🇨🇦", # Non-ascii
222222
"America/New\ud800York", # Contains surrogate character
223+
"a" * 256, # Too long
223224
]
224225

225226
for bad_key in bad_keys:

Lib/zoneinfo/_common.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def load_tzdata(key):
1010

1111
try:
1212
return resources.files(package_name).joinpath(resource_name).open("rb")
13-
except (ImportError, FileNotFoundError, UnicodeEncodeError):
13+
except (ImportError, FileNotFoundError, UnicodeEncodeError): # TODO
1414
# There are three types of exception that can be raised that all amount
1515
# to "we cannot find this key":
1616
#
@@ -21,6 +21,8 @@ def load_tzdata(key):
2121
# (e.g. Europe/Krasnoy)
2222
# UnicodeEncodeError: If package_name or resource_name are not UTF-8,
2323
# such as keys containing a surrogate character.
24+
# OSError: If filename is wrong (too long, has invalid ascii symbols)
25+
# or when there's a permissing error.
2426
raise ZoneInfoNotFoundError(f"No time zone found with key {key}")
2527

2628

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix :class:`zoneinfo.ZoneInfo` raising :exc:`OSError` instead of
2+
``ZoneInfoNotFoundError``.

0 commit comments

Comments
 (0)