Skip to content

Fix an occurrence of lazy_import #40541

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/sage/misc/lazy_import.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions src/sage/schemes/curves/projective_curve.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -1400,7 +1399,7 @@
sage: set_verbose(-1)
sage: P.<x,y,z> = ProjectiveSpace(QQ, 2)
sage: C = Curve([(x^2 + y^2 - y*z - 2*z^2)*(y*z - x^2 + 2*z^2)*z + y^5], P)
sage: C.ordinary_model() # long time (5 seconds)

Check warning on line 1402 in src/sage/schemes/curves/projective_curve.py

View workflow job for this annotation

GitHub Actions / Conda (ubuntu, Python 3.12, new)

Warning: slow doctest:

slow doctest:: Test ran for 113.84s cpu, 113.85s wall Check ran for 0.00s cpu, 0.00s wall
Scheme morphism:
From: Projective Plane Curve over Number Field in a
with defining polynomial y^2 - 2 defined
Expand Down Expand Up @@ -1450,9 +1449,10 @@
+ (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]
Expand Down Expand Up @@ -1804,7 +1804,7 @@
sage: C = P.curve(z^2*y^3 - z*(33*x*z+2*x^2+8*z^2)*y^2
....: + (21*z^2+21*x*z-x^2)*(z^2+11*x*z-x^2)*y
....: + (x-18*z)*(z^2+11*x*z-x^2)^2)
sage: G0 = C.fundamental_group() # needs sirocco

Check warning on line 1807 in src/sage/schemes/curves/projective_curve.py

View workflow job for this annotation

GitHub Actions / Conda (macos, Python 3.11, all)

Warning: slow doctest:

slow doctest:: Test ran for 5.31s cpu, 3.93s wall Check ran for 0.00s cpu, 0.00s wall

Check warning on line 1807 in src/sage/schemes/curves/projective_curve.py

View workflow job for this annotation

GitHub Actions / Conda (ubuntu, Python 3.11, all)

Warning: slow doctest:

slow doctest:: Test ran for 17.28s cpu, 16.02s wall Check ran for 0.00s cpu, 0.00s wall
sage: G.is_isomorphic(G0) # needs sirocco
True
sage: C = P.curve(z)
Expand Down
Loading