How to use the wrapt.importer._post_import_hooks function in wrapt

To help you get started, we’ve selected a few wrapt examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github DataDog / dd-trace-py / ddtrace / utils / install.py View on Github external
def _deregister_post_import_hook(modulename, matcher):
    """
    Deregisters post import hooks for a module given the module name and a
    matcher function. All hooks matching the matcher function will be removed.
    """
    hooks = _post_import_hooks.get(modulename, []) or []
    hooks = list(filter(lambda h: not matcher(h), hooks))

    # Work around for wrapt since wrapt assumes that if
    # _post_import_hooks.get(modulename) is not None then the module must have
    # been imported.
    if not len(hooks):
        hooks = None
    _post_import_hooks[modulename] = hooks