attribute_call_stringο
- plasmapy.utils.code_repr.attribute_call_string(
- cls,
- attr: str,
- args_to_cls: tuple | Any | None = None,
- kwargs_to_cls: dict[str, Any] | None = None,
- max_items: int = 12,
Approximate the command to instantiate a class, and access an attribute of the resulting class instance.
- Parameters:
cls (
class) β The class to be used in the string representation.attr (
str) β The name of the attribute of classcls.args_to_cls (
tuple,list, or anyobject; optional) β Atupleorlistcontaining positional arguments, or any other type ofobjectif there is only one positional argument, to be used during instantiation ofclskwargs_to_cls (
dict, optional) β Adictcontaining the keyword arguments to be used during instantiation ofcls.max_items (
int, default: 12) β The maximum number of items to include in andarrayorQuantity; additional items will be truncated with an ellipsis.
- Returns:
Approximation of a command to instantiate
clswithargs_to_clsas positional arguments andkwargs_to_clsas keyword arguments, and then access the attributeattr.- Return type:
See also
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
uforastropy.unitsandnpfornumpy.Examples
>>> class SampleClass: ... def __init__(self, arg1, kwarg1=None): ... pass ... ... @property ... def attribute(self): ... return 42 >>> args_to_cls = (1, 2) >>> kwargs_to_cls = {"kwarg1": 2} >>> attribute_call_string(SampleClass, "attribute", args_to_cls, kwargs_to_cls) 'SampleClass(1, 2, kwarg1=2).attribute'