line_profiler.autoprofile.line_profiler_utils module

line_profiler.autoprofile.line_profiler_utils.add_imported_function_or_module(self, item, *, scoping_policy=None, wrap=False)[source]

Method to add an object to LineProfiler to be profiled.

This method is used to extend an instance of LineProfiler so it can identify whether an object is a callable (wrapper), a class, or a module, and handle its profiling accordingly.

Parameters:
  • item (Union[Callable, Type, ModuleType]) – Object to be profiled.

  • scoping_policy (Union[ScopingPolicy, str, ScopingPolicyDict, None]) – Whether (and how) to match the scope of members and decide on whether to add them:

    str (incl. ScopingPolicy):

    Strings are converted to ScopingPolicy instances in a case-insensitive manner, and the same policy applies to all members.

    {'func': ..., 'class': ..., 'module': ...}

    Mapping specifying individual policies to be enacted for the corresponding member types.

    None

    The default, equivalent to DEFAULT_SCOPING_POLICIES.

    See line_profiler.line_profiler.ScopingPolicy and to_policies() for details.

  • wrap (bool) – Whether to replace the wrapped members with wrappers which automatically enable/disable the profiler when called.

Returns:

1 if any function is added to the profiler, 0 otherwise.

See also

DEFAULT_SCOPING_POLICIES, LineProfiler.add_callable(), LineProfiler.add_module(), LineProfiler.add_class(), ScopingPolicy, ScopingPolicy.to_policies()