stub42/pytz

Superset of all_timezones/common_timezones is hardcoded

bdrung opened this issue · 2 comments

On Debian-based systems (including Ubuntu) pytz is patched to use the tzdata information from the system. That allows updating tzdata without needing to update pytz every time.

The superset of all_timezones and common_timezones is hard-coded in the pytz release (in pytz/__init__.py). When tzdata adds a timezone or renames one (e.g. Ubuntu bug #1995864), pytz needs to be updated.

pytz should evaluate the available timezones on the system to work with future tzdata updates.

Bug-Ubuntu: https://launchpad.net/bugs/207604

pytz already gracefully handles timezones disappearing. There is still a problem when new timezones are introduced, such as recently with Europe/Kyiv.

To address this, pytz would need to replace pytz._all_timezones_unchecked with code that scans all available timezones on the system. Debian and Ubuntu are already patching pytz to correctly point it at the system timezone database. This patch could be extended with the necessary replacement code. This should leave systems using the pytz distributed timezone database unaffected and not needing to pay the runtime costs (some other checks could be turned off, so maybe this cost could be nullified, or maybe even improve speed).

It should also be possible to make a similar change to pytz, where if the timezone database is the standard directory + unpacked files and is not the pytz distributed version, then the scan is done. However, a preferable approach pay be to instead stop distributing the tzdata database with pytz at all, and instead switching to https://pypi.org/project/tzdata/ as part of the process of properly retiring pytz in favor of Python stdlib.

bdrung commented

I have implemented that patch for the Debian and Ubuntu package in 2022.7.1-2. My long term goal is get rid of pytz in Debian/Ubuntu and rely on zoneinfo from Python >= 3.9. So we are on the same page here.