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 (clean_namespace): Default for namespac…
Browse files Browse the repository at this point in the history
…e like lazy_import
  • Loading branch information
Matthias Koeppe committed Dec 18, 2022
1 parent 6e384f5 commit 4acb9d7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/sage/all.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ def quit_sage(verbose=True):
# Relink imported lazy_import objects to point to the appropriate namespace

from sage.misc.lazy_import import clean_namespace
clean_namespace(globals())
clean_namespace()
del clean_namespace

# From now on it is ok to resolve lazy imports
Expand Down
9 changes: 8 additions & 1 deletion src/sage/misc/lazy_import.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1195,7 +1195,7 @@ def attributes(a):
"_at_startup": b._at_startup,
"_deprecation": b._deprecation}

def clean_namespace(namespace):
def clean_namespace(namespace=None):
"""
Adjust :class:`LazyImport` bindings in given namespace to refer to this actual namespace.
Expand All @@ -1204,6 +1204,11 @@ def clean_namespace(namespace):
binding in the namespace to the actual imported object upon access is not adjusted.
This routine fixes that.
INPUT:
- ``namespace`` -- the namespace where importing the names; by default,
import the names to current namespace
EXAMPLES::
sage: from sage.misc.lazy_import import attributes, clean_namespace
Expand All @@ -1219,6 +1224,8 @@ def clean_namespace(namespace):
True
"""
cdef LazyImport w
if namespace is None:
namespace = inspect.currentframe().f_locals
for k,v in namespace.items():
if type(v) is LazyImport:
w = v
Expand Down

0 comments on commit 4acb9d7

Please sign in to comment.