Hello sage-dev,

this week I worked on something which I find quite exciting: a context ("with" statement) for lazy imports. See https://trac.sagemath.org/ticket/22752

The old lazy import

lazy_import('sage.arith.srange', 'xsrange', 'sxrange', deprecation=20094)

can now be written as

with lazyimport(deprecation=20094):
    from sage.arith.srange import xsrange as sxrange

In addition to the syntax change, two more issues are fixed for the new "lazyimport" context:

1. It works in Cython.
2. Lazy relative imports are supported.

This is implemented by overriding __builtin__.__import__ (which is a documented way to change the import mechanism).

The motivating reason to improve lazy imports was to work on fixing the cyclic import problem in Sage (#21636).


Enjoy (and please review),
Jeroen.

--
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at https://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.

Reply via email to