Skip to content

ZoneInfo gives a surprising exception for '' #114713

Open

Description

@asottile-sentry

Bug report

Bug description:

import zoneinfo
zoneinfo.ZoneInfo('')

results in the following exception:

>>> zoneinfo.ZoneInfo('')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/asottile/.pyenv/versions/3.11.6/lib/python3.11/zoneinfo/_tzpath.py", line 67, in find_tzfile
    _validate_tzfile_path(key)
  File "/Users/asottile/.pyenv/versions/3.11.6/lib/python3.11/zoneinfo/_tzpath.py", line 91, in _validate_tzfile_path
    raise ValueError(
ValueError: ZoneInfo keys must be normalized relative paths, got: 

I expect zoneinfo.ZoneInfoNotFound instead, or some other error that's more specific about this case

it seems this stems from the code internally using the length of the normpath'd result of this string and:

>>> normpath('')
'.'

a small improvement would be to use !r in the error message as well

CPython versions tested on:

3.11, CPython main branch

Operating systems tested on:

macOS

Linked PRs

Activity

  1. added
    type-bug
    on Jan 29, 2024
  2. added
    stdlib
    3.11
    3.12
    3.13
    on Jan 29, 2024
  3. removed
    3.11
    3.12
    3.13
    on Mar 10, 2025
  4. added a commit that references this issue on Apr 15, 2025
  5. added a commit that references this issue on Apr 15, 2025
  6. added a commit that references this issue on Apr 15, 2025
  7. added 2 commits that reference this issue on May 3, 2025
  8. added a commit that references this issue on May 3, 2025
  9. added a commit that references this issue on May 3, 2025
  10. added a commit that references this issue on Jul 12, 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

    stdlibtype-bug

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions