From f44e0811984664c9ec57bf70c11e2b93c55b0056 Mon Sep 17 00:00:00 2001 From: user202729 <25191436+user202729@users.noreply.github.com> Date: Mon, 4 Aug 2025 06:23:49 +0700 Subject: [PATCH 1/2] Fix LazyImport --- src/sage/misc/lazy_import.pyx | 17 +++++++++++++++++ src/sage/schemes/curves/projective_curve.py | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/sage/misc/lazy_import.pyx b/src/sage/misc/lazy_import.pyx index 58365b2b272..9bac24a371e 100644 --- a/src/sage/misc/lazy_import.pyx +++ b/src/sage/misc/lazy_import.pyx @@ -36,6 +36,23 @@ that (s)he can remove the flag:: UserWarning: Option ``at_startup=True`` for lazy import ZZ not needed anymore Integer Ring +.. WARNING:: + + After the first usage, the imported object is directly injected into the + namespace; however, before that, the :class:`LazyImport` object + is not exactly equivalent to the actual imported object. For example:: + + sage: from sage.misc.lazy_import import LazyImport + sage: my_qqbar = LazyImport('sage.rings.qqbar', 'QQbar') + sage: my_qqbar(5) == QQbar(5) # good + True + sage: isinstance(QQbar, Parent) + True + sage: isinstance(my_qqbar, Parent) # fails! + False + + To avoid this issue, you may execute the import inside the function instead. + .. SEEALSO:: :func:`lazy_import`, :class:`LazyImport` AUTHOR: diff --git a/src/sage/schemes/curves/projective_curve.py b/src/sage/schemes/curves/projective_curve.py index 09fb3ffd3db..cd4462112ff 100644 --- a/src/sage/schemes/curves/projective_curve.py +++ b/src/sage/schemes/curves/projective_curve.py @@ -159,7 +159,6 @@ lazy_import('sage.interfaces.singular', 'singular') lazy_import('sage.rings.number_field.number_field', 'NumberField') -lazy_import('sage.rings.qqbar', ['number_field_elements_from_algebraics', 'QQbar']) from .curve import Curve_generic @@ -1452,6 +1451,7 @@ def ordinary_model(self): """ # helper function for extending the base field + from sage.rings.qqbar import number_field_elements_from_algebraics, QQbar def extension(self): F = self.base_ring() pts = self.change_ring(F.embeddings(QQbar)[0]).rational_points() From fc2661696d342d0f7cfe45309957f6478dc5283a Mon Sep 17 00:00:00 2001 From: user202729 <25191436+user202729@users.noreply.github.com> Date: Mon, 4 Aug 2025 17:39:12 +0700 Subject: [PATCH 2/2] Fix lint --- src/sage/schemes/curves/projective_curve.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sage/schemes/curves/projective_curve.py b/src/sage/schemes/curves/projective_curve.py index cd4462112ff..f65da51e1e7 100644 --- a/src/sage/schemes/curves/projective_curve.py +++ b/src/sage/schemes/curves/projective_curve.py @@ -1449,10 +1449,10 @@ def ordinary_model(self): + (1/16*a + 1/16)*x*y*z^2 + (3/16*a + 3/16)*y^2*z^2 + (-3/16*a - 1/4)*y*z^3 + (1/16*a + 3/32)*z^4) """ - # helper function for extending the base field - from sage.rings.qqbar import number_field_elements_from_algebraics, QQbar + def extension(self): + # helper function for extending the base field F = self.base_ring() pts = self.change_ring(F.embeddings(QQbar)[0]).rational_points() L = [t for pt in pts for t in pt]