The import of pytz on my system is quite fast due to the use of lazy lists, but as soon as a single timezone is used the entire list is still processed. A minimal example:
all_timezones = LazyList((tz for tz in all_timezones if resource_exists(tz)))
The all_timezones is lazy, but the call to pytz.timezone ends up executing this piece of code
def _case_insensitive_zone_lookup(zone):
"""case-insensitively matching timezone, else return zone unchanged"""
global _all_timezones_lower_to_standard
if _all_timezones_lower_to_standard is None:
_all_timezones_lower_to_standard = dict((tz.lower(), tz) for tz in all_timezones) # noqa
return _all_timezones_lower_to_standard.get(zone.lower()) or zone # noqa
This results in the entire lazy list being processed.
Can the pytz code be refactored so that the call to pytz.timezone is more efficient?
The import of pytz on my system is quite fast due to the use of lazy lists, but as soon as a single timezone is used the entire list is still processed. A minimal example:
Has output:
The reason is the following line from
__init__.py
The
all_timezones
is lazy, but the call topytz.timezone
ends up executing this piece of codeThis results in the entire lazy list being processed.
Can the pytz code be refactored so that the call to
pytz.timezone
is more efficient?@stub42