def _patch_import_to_patch_pyqt_on_import(patch_qt_on_import):
# I don't like this approach very much as we have to patch __import__, but I like even less
# asking the user to configure something in the client side...
# So, our approach is to patch PyQt4/5 right before the user tries to import it (at which
# point he should've set the sip api version properly already anyways).
dotted = patch_qt_on_import + '.'
original_import = __import__
from _pydev_imps._pydev_sys_patch import patch_sys_module, patch_reload, cancel_patches_in_sys_module
patch_sys_module()
patch_reload()
def patched_import(name, *args, **kwargs):
if patch_qt_on_import == name or name.startswith(dotted):
builtins.__import__ = original_import
cancel_patches_in_sys_module()
_internal_patch_qt() # Patch it only when the user would import the qt module
return original_import(name, *args, **kwargs)
try:
import builtins
except ImportError:
import __builtin__ as builtins
builtins.__import__ = patched_import
评论列表
文章目录