Skip to content

Commit aa165bc

Browse files
committed
Fix error message for empty bytes object; adjust the check for an empty string
1 parent 82f74eb commit aa165bc

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

Lib/test/test_zoneinfo/test_zoneinfo.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ def test_bad_keys_paths(self):
237237
"America/../America/Los_Angeles", # Not normalized
238238
"America/./Los_Angeles",
239239
"",
240+
b"",
240241
]
241242

242243
for bad_key in bad_keys:

Lib/zoneinfo/_tzpath.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,14 @@ def find_tzfile(key):
8383

8484

8585
def _validate_tzfile_path(path, _base=_TEST_PATH):
86-
if not path:
86+
if path == "":
8787
raise ValueError(
8888
"ZoneInfo key must not be an empty string"
8989
)
90+
elif path == b"":
91+
raise ValueError(
92+
"ZoneInfo key must not be an empty bytes object"
93+
)
9094

9195
if os.path.isabs(path):
9296
raise ValueError(
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Handle case of an empty bytes object passed to :class:`zoneinfo.ZoneInfo`.
2+

0 commit comments

Comments
 (0)