Skip to content

LazyImport is breaking my personal modules #41213

@mcmillanbb

Description

@mcmillanbb

Steps To Reproduce

I create helper.py with the following class:

class Example:
    def __init__(self, V):
        super().__init__(V)

Then in a separate file in the same folder, which imports helper, if I call Example(V), I get ModuleNotFoundError: No module named 'Example'. This is in the sage interpreter, via a jupyter notebook.

Expected Behavior

This should rather create an instance of Example. If I don't call super, then the instantiation works fine.

Actual Behavior

It seems that sage has added my class into its lazy import system, and I cannot get it out. The lazy import assumes a module, but it does not exist, because I have only made a lightweight helper script.

Additional Information

The full traceback is this:

ModuleNotFoundError Traceback (most recent call last)
Cell In[1], line 2
1 Example2(V)
----> 2 Example(V)

File /private/var/tmp/sage-10.7-current/local/lib/python3.13/site-packages/sage/misc/lazy_import.pyx:397, in sage.misc.lazy_import.LazyImport.call (build/cythonized/sage/misc/lazy_import.c:6670)()
395 True
396 """
--> 397 return self.get_object()(*args, **kwds)
398
399 def repr(self):

File /private/var/tmp/sage-10.7-current/local/lib/python3.13/site-packages/sage/misc/lazy_import.pyx:215, in sage.misc.lazy_import.LazyImport.get_object (build/cythonized/sage/misc/lazy_import.c:4664)()
213 if likely(self._object is not None):
214 return self._object
--> 215 return self._get_object()
216
217 cpdef _get_object(self):

File /private/var/tmp/sage-10.7-current/local/lib/python3.13/site-packages/sage/misc/lazy_import.pyx:256, in sage.misc.lazy_import.LazyImport._get_object (build/cythonized/sage/misc/lazy_import.c:5175)()
254 from sage.features import FeatureNotPresentError
255 raise FeatureNotPresentError(feature, reason=f'Importing {self._name} failed: {e}')
--> 256 raise
257
258 if feature:

File /private/var/tmp/sage-10.7-current/local/lib/python3.13/site-packages/sage/misc/lazy_import.pyx:250, in sage.misc.lazy_import.LazyImport._get_object (build/cythonized/sage/misc/lazy_import.c:5018)()
248 feature = self._feature
249 try:
--> 250 self._object = getattr(import(self._module, {}, {}, [self._name]), self._name)
251 except ImportError as e:
252 if feature:

ModuleNotFoundError: No module named 'Example'

Environment

  • OS: Mac 15.6
  • Sage Version: 10.7

Checklist

  • I have searched the existing issues for a bug report that matches the one I want to file, without success.
  • I have read the documentation and troubleshoot guide

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions