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 dc2ddb5
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 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

0 comments on commit dc2ddb5

Please sign in to comment.