From dc2ddb5a759628bab508ae6354e1d8eceaadd138 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Mon, 18 Jul 2022 10:31:13 -0700 Subject: [PATCH] src/sage/misc/lazy_import.pyx: Improve deprecation message when as_ is in use --- src/sage/misc/lazy_import.pyx | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/sage/misc/lazy_import.pyx b/src/sage/misc/lazy_import.pyx index 97055afb01a..7774ccaa73a 100644 --- a/src/sage/misc/lazy_import.pyx +++ b/src/sage/misc/lazy_import.pyx @@ -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