-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
Open
Labels
stdlibPython modules in the Lib dirPython modules in the Lib dirtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Bug report
According to documentation all calls to ZoneInfo should raise ValueError
or ZoneInfoNotFoundError
.
Creating a ZoneInfo object with an invalid very long timezone (length > 255) an OSError is raised instead (OSError: [Errno 36] File name too long
).
I believe that
cpython/Lib/zoneinfo/_common.py
Lines 11 to 24 in 29f1b0b
try: | |
return resources.files(package_name).joinpath(resource_name).open("rb") | |
except (ImportError, FileNotFoundError, UnicodeEncodeError): | |
# There are three types of exception that can be raised that all amount | |
# to "we cannot find this key": | |
# | |
# ImportError: If package_name doesn't exist (e.g. if tzdata is not | |
# installed, or if there's an error in the folder name like | |
# Amrica/New_York) | |
# FileNotFoundError: If resource_name doesn't exist in the package | |
# (e.g. Europe/Krasnoy) | |
# UnicodeEncodeError: If package_name or resource_name are not UTF-8, | |
# such as keys containing a surrogate character. | |
raise ZoneInfoNotFoundError(f"No time zone found with key {key}") |
OSError
exception raised by open and reraise it to ZoneInfoNotFoundError
.
Sample code for reproduction:
from zoneinfo import ZoneInfo
ZoneInfo("a"*256)
Your environment
- CPython versions tested on: Python 3.10.4
- Operating system and architecture: Debian GNU/Linux 11 (bullseye)
Linked PRs
Metadata
Metadata
Assignees
Labels
stdlibPython modules in the Lib dirPython modules in the Lib dirtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Projects
Status
No status