Skip to content

Commit a7d331a

Browse files
author
Release Manager
committed
sagemathgh-40541: Fix an occurrence of lazy_import Previously the following code fails if executed right after Sage starts: ```python P.<x,y,z> = ProjectiveSpace(QQ, 2) C = Curve([(x^2 + y^2 - y*z - 2*z^2)*(y*z - x^2 + 2*z^2)*z + y^5], P) C.ordinary_model() ``` The error is: ```python NotImplementedError: object does not support iteration ``` This pull request fixes it. The reason why it is fixed is explained in the code edit. ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. - [ ] I have linked a relevant issue or discussion. - [ ] I have created tests covering the changes. - [x] I have updated the documentation and checked the documentation preview. ### ⌛ Dependencies <!-- List all open PRs that this PR logically depends on. For example, --> <!-- - sagemath#12345: short description why this is a dependency --> <!-- - sagemath#34567: ... --> URL: sagemath#40541 Reported by: user202729 Reviewer(s): grnx
2 parents a65f636 + fc26616 commit a7d331a

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

src/sage/misc/lazy_import.pyx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,23 @@ that (s)he can remove the flag::
3636
UserWarning: Option ``at_startup=True`` for lazy import ZZ not needed anymore
3737
Integer Ring
3838
39+
.. WARNING::
40+
41+
After the first usage, the imported object is directly injected into the
42+
namespace; however, before that, the :class:`LazyImport` object
43+
is not exactly equivalent to the actual imported object. For example::
44+
45+
sage: from sage.misc.lazy_import import LazyImport
46+
sage: my_qqbar = LazyImport('sage.rings.qqbar', 'QQbar')
47+
sage: my_qqbar(5) == QQbar(5) # good
48+
True
49+
sage: isinstance(QQbar, Parent)
50+
True
51+
sage: isinstance(my_qqbar, Parent) # fails!
52+
False
53+
54+
To avoid this issue, you may execute the import inside the function instead.
55+
3956
.. SEEALSO:: :func:`lazy_import`, :class:`LazyImport`
4057
4158
AUTHOR:

src/sage/schemes/curves/projective_curve.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,6 @@
159159

160160
lazy_import('sage.interfaces.singular', 'singular')
161161
lazy_import('sage.rings.number_field.number_field', 'NumberField')
162-
lazy_import('sage.rings.qqbar', ['number_field_elements_from_algebraics', 'QQbar'])
163162

164163
from .curve import Curve_generic
165164

@@ -1450,9 +1449,10 @@ def ordinary_model(self):
14501449
+ (1/16*a + 1/16)*x*y*z^2 + (3/16*a + 3/16)*y^2*z^2
14511450
+ (-3/16*a - 1/4)*y*z^3 + (1/16*a + 3/32)*z^4)
14521451
"""
1453-
# helper function for extending the base field
1452+
from sage.rings.qqbar import number_field_elements_from_algebraics, QQbar
14541453

14551454
def extension(self):
1455+
# helper function for extending the base field
14561456
F = self.base_ring()
14571457
pts = self.change_ring(F.embeddings(QQbar)[0]).rational_points()
14581458
L = [t for pt in pts for t in pt]

0 commit comments

Comments
 (0)