Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Lazy-load dateutil submodules? #771

@pganssle

Description

@pganssle

It is a fairly common problem (see, e.g. issue #770) that people assume that import dateutil will automatically import all of dateutil's sub-modules. Currently we don't do this because we want to be as lazy as possible about imports.

We'll need to profile it, but I think there is a "best of both worlds" option here, where in dateutil.__init__ we define lazy-loaded modules, so that the first time you invoke, e.g. dateutil.tz dateutil.tz will be imported in the background, and subsequent queries come from a cache.

For Python 3.7+, I think the best / fastest way to do this is to use module-level __getattr__ and __dir__ implementations, but for pre-Python 3.7, we may need to do something fancy and module sys.modules or something to implement the equivalent to a module-level __getattr__.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions