Skip to content

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

Closed

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

Activity

  1. added
    type-bugAn unexpected behavior, bug, or error
    on Sep 3, 2025
  2. added
    stdlibStandard Library Python modules in the Lib/ directory
    on Sep 3, 2025
  3. JuanHPassos commented on Sep 9, 2025

    @JuanHPassos

    Hello,

    I would like to try to fix this issue, this would be my first contribution to CPython.

    I've read the bug report and the traceback, and it seems the problem is a TypeError being raised instead of a ValueError because the path objects are not being converted to strings before being joined for the error message.

    Would it be okay for me to work on a fix? I will be sure to follow the dev guide.

    Thank you!

  4. tungol commented on Sep 9, 2025

    @tungol
    ContributorAuthor

    Hi @JuanHPassos

    You don't really need anyone's permission to work on an issue, but in this case I already have a PR up that would resolve the issue: #138433

  5. added a commit that references this issue on Sep 11, 2025
  6. added a commit that references this issue on Sep 11, 2025
  7. added a commit that references this issue on Sep 11, 2025
  8. added
    3.13only security fixes
    3.14bugs and security fixes
    3.15bugs and security fixes
    on Sep 11, 2025
  9. added a commit that references this issue on Sep 11, 2025
  10. added a commit that references this issue on Oct 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions