Skip to main content

debug_import

Prints a debug message identifying the calling module and the name of the package being imported before delegating the actual import process to a specified import function.

def debug_import(
name: string,
locals: dict = null,
globals: dict = null,
fromlist: list = null,
level: integer = -1,
real_import: callable = builtins.__import__
) - > module

Logs the name of the module being imported and the name of the calling module to stdout before executing the standard import logic. Use this to trace module dependency chains and identify which parts of an application are triggering specific imports.

Parameters

NameTypeDescription
namestringThe absolute or relative name of the module to be imported.
localsdict = nullThe local namespace mapping, typically used to determine the context of the import.
globalsdict = nullThe global namespace mapping used to identify the calling module's name; defaults to the caller's frame globals if not provided.
fromlistlist = nullA list of names to be imported from the module (e.g., ['func1', 'func2'] in 'from mod import func1, func2').
levelinteger = -1Determines whether to perform absolute or relative imports; 0 is absolute, while positive integers represent the number of parent directories to search relative to the current module.
real_importcallable = builtins.importThe underlying import function to execute after logging; defaults to the standard Python import builtin.

Returns

TypeDescription
moduleThe module object that was imported, or the package if fromlist is empty.