Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
src/sage/misc/lazy_import.pyx: Improve deprecation message when as_ i…
Browse files Browse the repository at this point in the history
…s in use
  • Loading branch information
Matthias Koeppe committed Jul 18, 2022
1 parent 7a0ff3f commit adb89ff
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/sage/misc/lazy_import.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -255,18 +255,19 @@ cdef class LazyImport():
raise FeatureNotPresentError(self._feature, reason=f'Importing {self._name} failed: {e}')
raise

name = self._as_name
if self._deprecation is not None:
from sage.misc.superseded import deprecation_cython as deprecation
try:
trac_number, message = self._deprecation
except TypeError:
trac_number = self._deprecation
message = ('\nImporting {name} from here is deprecated. ' +
'If you need to use it, please import it directly from' +
' {module_name}').format(name=name, module_name=self._module)
import_command = f'from {self._module} import {self._name}'
if self._as_name != self._name:
import_command += f' as {self._as_name}'
message = f'\nImporting {self._as_name} from here is deprecated; please use "{import_command}" instead.'
deprecation(trac_number, message)
# Replace the lazy import in the namespace by the actual object
name = self._as_name
if self._namespace is not None:
if self._namespace.get(name) is self:
self._namespace[name] = self._object
Expand Down Expand Up @@ -1028,7 +1029,7 @@ def lazy_import(module, names, as_=None, *,
sage: lazy_import('sage.all', 'Qp', 'my_Qp', deprecation=14275)
sage: my_Qp(5)
doctest:...: DeprecationWarning:
Importing my_Qp from here is deprecated. If you need to use it, please import it directly from sage.all
Importing my_Qp from here is deprecated; please use "from sage.all import Qp as my_Qp" instead.
See http://trac.sagemath.org/14275 for details.
5-adic Field with capped relative precision 20
Expand Down

0 comments on commit adb89ff

Please sign in to comment.