-
-
Notifications
You must be signed in to change notification settings - Fork 710
Closed
Milestone
Description
The LazyImport objects suffer several problems
copyanddeepcopyare broken
sage: from sage.misc.lazy_import import LazyImport
sage: sage.all.foo = [1, 2]
sage: lazy_foo = LazyImport('sage.all', 'foo')
sage: a = copy(lazy_foo)
sage: a
[1, 2]
sage: a[0] = 18
sage: lazy_foo
[18, 2]
- Most doctests use
lazy_importrather thanLazyImport. The former modifies the namespace so that the name actually points to the object afterwards. Compare
sage: lazy_import('sage.rings.all', 'ZZ', 'lazy_ZZ')
sage: type(lazy_ZZ)
<class 'sage.misc.lazy_import.LazyImport'>
sage: _ = lazy_ZZ(3)
sage: type(lazy_ZZ)
<class 'sage.rings.integer_ring.IntegerRing_class'>
with
sage: from sage.misc.lazy_import import LazyImport
sage: lazy_ZZ = LazyImport('sage.rings.all', 'ZZ')
sage: _ = lazy_ZZ(3)
sage: type(lazy_ZZ)
<class 'sage.misc.lazy_import.LazyImport'>
In the former version, any code that uses more than once the lazy object actually uses it only once.
- It is not checked that lazy imported module resolves correctly... and it is not the case
sage: LinearCodeFromVectorSpace._get_object()
Traceback (most recent call last):
...
AttributeError: module 'sage.coding.linear_code' has no attribute 'LinearCodeFromVectorSpace'
Follow-up: #31656
Depends on #31648
CC: @kliem
Component: misc
Author: Vincent Delecroix
Branch/Commit: 99ad007
Reviewer: Travis Scrimshaw
Issue created by migration from https://trac.sagemath.org/ticket/31650