Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Lib/test/test_zoneinfo/test_zoneinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ def test_bad_keys(self):
"America.Los_Angeles",
"🇨🇦", # Non-ascii
"America/New\ud800York", # Contains surrogate character
"Europe" # Is a directory, see issue 85702
]

for bad_key in bad_keys:
Expand Down
3 changes: 2 additions & 1 deletion Lib/zoneinfo/_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def load_tzdata(key):

try:
return resources.files(package_name).joinpath(resource_name).open("rb")
except (ImportError, FileNotFoundError, UnicodeEncodeError):
except (ImportError, FileNotFoundError, UnicodeEncodeError, IsADirectoryError):
# There are three types of exception that can be raised that all amount
# to "we cannot find this key":
#
Expand All @@ -21,6 +21,7 @@ def load_tzdata(key):
# (e.g. Europe/Krasnoy)
# UnicodeEncodeError: If package_name or resource_name are not UTF-8,
# such as keys containing a surrogate character.
# IsADirectoryError: If package_name without a resource_name specified.
raise ZoneInfoNotFoundError(f"No time zone found with key {key}")


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
If ``zoneinfo._common.load_tzdata`` is given a package without a resource a
``ZoneInfoNotFoundError`` is raised rather than a :exc:`IsADirectoryError`.
Loading