Skip to content

zoneinfo.reset_tzpath raises TypeError instead of ValueError if passed a sequence with a relative Pathlike #138432

@tungol

Description

@tungol

Bug report

Bug description:

Documentation for zoneinfo.reset_tzpath states:

The to parameter must be a sequence of strings or os.PathLike and not a string, all of which must be absolute paths. ValueError will be raised if something other than an absolute path is passed.

However, the error pathway for relative paths does not currently handle os.PathLike instances correctly.

>>> zoneinfo.reset_tzpath((pathlib.Path("path/to/somewhere"),))
Traceback (most recent call last):
  File "<python-input-6>", line 1, in <module>
    zoneinfo.reset_tzpath((pathlib.Path("path/to/somewhere"),))
    ~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.14/lib/python3.14/zoneinfo/_tzpath.py", line 33, in reset_tzpath
    _reset_tzpath(to)
    ~~~~~~~~~~~~~^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.14/lib/python3.14/zoneinfo/_tzpath.py", line 17, in _reset_tzpath
    raise ValueError(_get_invalid_paths_message(tzpaths))
                     ~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.14/lib/python3.14/zoneinfo/_tzpath.py", line 63, in _get_invalid_paths_message
    indented_str = prefix + prefix.join(invalid_paths)
                            ~~~~~~~~~~~^^^^^^^^^^^^^^^
TypeError: sequence item 0: expected str instance, PosixPath found

CPython versions tested on:

3.14

Operating systems tested on:

macOS

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.13bugs and security fixes3.14bugs and security fixes3.15new features, bugs and security fixesstdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions