Skip to content

Commit d22604a

Browse files
gh-85702: Catch IsADirectoryError in zoneinfo (#131333)
Co-authored-by: Victor Stinner <[email protected]>
1 parent bd47ec9 commit d22604a

File tree

3 files changed

+5
-1
lines changed

3 files changed

+5
-1
lines changed

Diff for: Lib/test/test_zoneinfo/test_zoneinfo.py

+1
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ def test_bad_keys(self):
222222
"America.Los_Angeles",
223223
"🇨🇦", # Non-ascii
224224
"America/New\ud800York", # Contains surrogate character
225+
"Europe", # Is a directory, see issue gh-85702
225226
]
226227

227228
for bad_key in bad_keys:

Diff for: Lib/zoneinfo/_common.py

+2-1
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, IsADirectoryError):
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,7 @@ 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+
# IsADirectoryError: If package_name without a resource_name specified.
2425
raise ZoneInfoNotFoundError(f"No time zone found with key {key}")
2526

2627

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

0 commit comments

Comments
 (0)