Skip to content

Add at_startup flag to lazy_import #14722

@nthiery

Description

@nthiery

Lazy imports have two main use cases:
(a) Delaying imports that are not always needed for a faster Sage startup
(b) Resolving import loops

This ticket introduce an option "at_startup" to allow for lazy imports
that are known to be resolved at startup time. The main use case is
(b) in the context of #10963. E.g. the categories Magmas and
Semigroups import each other reciprocally (because Magmas.Associative
points to Semigroups). It is natural to resolve this by defining
Magmas.Associative using a lazy import; one can then play with
Magmas() without having to load Semigroups. However Semigroups() is
later constructed during Sage's startup (and this is unlikely to
change).

This option could also be used as an intermediate step toward (a),
when a module is used in several places and some of those places can
already afford to lazy import the module but not yet others. As a
bonus, a lazy import that is marked as "at_startup" will print a
message if it is actually resolved after the startup, so that the
developer know that (s)he can remove the flag.

CC: @rishikesha @jasongrout @rlmill @mwhansen @simon-king-jena

Component: misc

Author: Nicolas M. Thiéry

Reviewer: Travis Scrimshaw

Merged: sage-5.12.beta1

Issue created by migration from https://trac.sagemath.org/ticket/14722

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions