call_string

plasmapy.utils.code_repr.call_string(f: Callable, args: Any = None, kwargs: dict[str, Any] | None = None, max_items: int = 12) str[source]

Approximate a call of a function or class with positional and keyword arguments.

Parameters:
  • f (callable) – A function, class, or other callable object.

  • args (tuple, list, or any object; optional) – A tuple or list containing positional arguments, or any other object if there is only one positional argument.

  • kwargs (dict, optional) – A dict containing keyword arguments.

  • max_items (int, default: 12) – The maximum number of items to include in a ndarray or Quantity; additional items will be truncated with an ellipsis.

Returns:

Approximation to a call of f with args as positional arguments and kwargs as keyword arguments.

Return type:

str

Notes

This function will generally provide an exact call string for most common types of simple positional and keyword arguments. When dealing with types that are not accounted for, this function will fall back on repr.

This function assumes aliases of u for astropy.units and np for numpy.

Examples

>>> call_string(int, 3.14159)
'int(3.14159)'
>>> call_string(int, args=(9.2,), kwargs={"base": 2})
'int(9.2, base=2)'