Skip to content

Commit

Permalink
src/sage/misc/lazy_import.pyx: Add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias Koeppe committed Sep 25, 2022
1 parent 3da1811 commit e5d1070
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/sage/misc/lazy_import.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,17 @@ from warnings import warn
import inspect
from . import sageinspect


# LazyImport.__repr__ uses try... except FeatureNotPresentError.
# This is defined in sage.features, provided by the distribution sagemath-environment.
try:
from sage.features import FeatureNotPresentError
except ImportError:
# If sage.features cannot be imported, then FeatureNotPresentError cannot
# be raised. In this case, use the empty tuple as the exception specification.
FeatureNotPresentError = ()


cdef inline obj(x):
if type(x) is LazyImport:
return (<LazyImport>x).get_object()
Expand Down Expand Up @@ -255,6 +261,7 @@ cdef class LazyImport():
self._object = getattr(__import__(self._module, {}, {}, [self._name]), self._name)
except ImportError as e:
if self._feature:
# Avoid warnings from static type checkers by explicitly importing FeatureNotPresentError.
from sage.features import FeatureNotPresentError
raise FeatureNotPresentError(self._feature, reason=f'Importing {self._name} failed: {e}')
raise
Expand Down

0 comments on commit e5d1070

Please sign in to comment.