Skip to content
Snippets Groups Projects
Commit 2e780411 authored by Jordi Gutiérrez Hermoso's avatar Jordi Gutiérrez Hermoso
Browse files

demandimport: define a `deactivated` context manager

This can be useful for use in "with" blocks for temporarily disabling
demandimport.
parent 238e5cd9
No related branches found
No related tags found
No related merge requests found
......@@ -25,6 +25,8 @@
'''
import __builtin__, os, sys
from contextlib import contextmanager
_origimport = __import__
nothing = object()
......@@ -179,3 +181,16 @@
def disable():
"disable global demand-loading of modules"
__builtin__.__import__ = _origimport
@contextmanager
def deactivated():
"context manager for disabling demandimport in 'with' blocks"
demandenabled = isenabled()
if demandenabled:
disable()
try:
yield
finally:
if demandenabled:
enable()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment