Skip to content

ZoneInfo gives a surprising exception for '' #114713

Closed
@asottile-sentry

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibPython modules in the Lib dirtype-bugAn unexpected behavior, bug, or error

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions