Skip to content

Commit 49bdcac

Browse files
committed
check that all paths are strings
1 parent bb1addc commit 49bdcac

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

Lib/zoneinfo/_tzpath.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@ def _reset_tzpath(to=None, stacklevel=4):
1313
+ f"not {type(tzpaths)}: {tzpaths!r}"
1414
)
1515

16+
tzpaths = [os.fspath(p) for p in tzpaths]
17+
nonstr_paths = [p for p in tzpaths if not isinstance(p, str)]
18+
if nonstr_paths:
19+
raise TypeError(
20+
"All elements of a tzpath sequence must be strings or "
21+
"os.PathLike objects which convert to strings."
22+
)
23+
1624
if not all(map(os.path.isabs, tzpaths)):
1725
raise ValueError(_get_invalid_paths_message(tzpaths))
1826
base_tzpath = tzpaths
@@ -57,7 +65,7 @@ def _parse_python_tzpath(env_var, stacklevel):
5765

5866

5967
def _get_invalid_paths_message(tzpaths):
60-
invalid_paths = (os.fspath(path) for path in tzpaths if not os.path.isabs(path))
68+
invalid_paths = (path for path in tzpaths if not os.path.isabs(path))
6169

6270
prefix = "\n "
6371
indented_str = prefix + prefix.join(invalid_paths)

0 commit comments

Comments
 (0)