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
| try: |
| returnresources.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. |
| raiseZoneInfoNotFoundError(f"No time zone found with key {key}") |
should also handle the
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
Bug report
According to documentation all calls to ZoneInfo should raise
ValueErrororZoneInfoNotFoundError.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
OSErrorexception raised by open and reraise it toZoneInfoNotFoundError.Sample code for reproduction:
Your environment
Linked PRs
load_tzdataraisingOSError, not `ZoneInfoNotFound… #99602