Helper functions¶
This module contains helper functions to ease the transition from pytz
to
another PEP 495-compatible library.
- pytz_deprecation_shim.helpers.is_pytz_zone(tz)¶
Check if a time zone is a
pytz
time zone.This will only import
pytz
if it has already been imported, and does not rely on the existence of thelocalize
ornormalize
methods (since the shim classes also have these methods, but are notpytz
zones).
- pytz_deprecation_shim.helpers.upgrade_tzinfo(tz)¶
Convert a
pytz
or shim timezone into its modern equivalent.The shim classes are thin wrappers around
zoneinfo
ordateutil.tz
implementations of thedatetime.tzinfo
base class. This function removes the shim and returns the underlying “upgraded” time zone.When passed a
pytz
zone (not a shim), this returns the non-pytz
equivalent. This may fail ifpytz
is using a data source incompatible with the upgraded provider’s data source, or if thepytz
zone was built from a file rather than an IANA key.When passed an object that is not a shim or a
pytz
zone, this returns the original object.- Parameters
tz – A
datetime.tzinfo
object.- Raises
KeyError – If a
pytz
zone is passed to the function with no equivalent in the PEP 495-compatible library’s version of the Olson database.- Returns
A PEP 495-compatible equivalent of any
pytz
or shim class, or the original object.