Skip to content

Commit bd7a086

Browse files
Catch IsADirectoryError
1 parent e82c2ca commit bd7a086

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

Lib/test/test_zoneinfo/test_zoneinfo.py

Lines changed: 1 addition & 0 deletions
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 85702
225226
]
226227

227228
for bad_key in bad_keys:

Lib/zoneinfo/_common.py

Lines changed: 2 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, 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

0 commit comments

Comments
 (0)