LazyList all_timezones is always evaluated at pytz import

Bug #1835784 reported by kmichel
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
pytz
Fix Released
Undecided
Unassigned

Bug Description

Despite the effort to use a LazyList for all_timezones,
the list of timezones is always evaluated as soon as pytz is imported.

This is caused by this line in the distributed file pytz/__init__.py
(this is added by gen_tzinfo.py and not directly visible in the repo):

_all_timezones_lower_to_standard = dict((tz.lower(), tz) for tz in all_timezones)

This line was added for the case insensitive lookup in this commit:

https://git.launchpad.net/pytz/commit/?id=78d76e59e52761b30cdf413be23d7d5e57ed416c

This addition cause a startup delay of about 540ms on my computer.

Without the line:
import time: self [us] | cumulative | imported package
[...]
import time: 34059 | 41445 | pytz

With the line (using python -X importtime):
import time: self [us] | cumulative | imported package
[...]
import time: 577866 | 586989 | pytz

(As a reference point, boto3 needs 240ms and numpy needs 1200ms).

description: updated
Stuart Bishop (stub)
Changed in pytz:
status: New → Triaged
Revision history for this message
Stuart Bishop (stub) wrote :

This can be deferred until timezone lookup time

Changed in pytz:
status: Triaged → Fix Committed
Stuart Bishop (stub)
Changed in pytz:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.