Skip to content

Commit edeab39

Browse files
committed
Add comment explaining tzdata exceptions
1 parent 1ce93da commit edeab39

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

Lib/zoneinfo/_common.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,16 @@ def load_tzdata(key):
1111
try:
1212
return importlib.resources.open_binary(package_name, resource_name)
1313
except (ImportError, FileNotFoundError, UnicodeEncodeError) as e:
14+
# There are three types of exception that can be raised that all amount
15+
# to "we cannot find this key":
16+
#
17+
# ImportError: If package_name doesn't exist (e.g. if tzdata is not
18+
# installed, or if there's an error in the folder name like
19+
# Amrica/New_York)
20+
# FileNotFoundError: If resource_name doesn't exist in the package
21+
# (e.g. Europe/Krasnoy)
22+
# UnicodeEncodeError: If package_name or resource_name are not UTF-8,
23+
# such as keys containing a surrogate character.
1424
raise ZoneInfoNotFoundError(f"No time zone found with key {key}") from e
1525

1626

0 commit comments

Comments
 (0)