attr_ module¶
Utilities for working with class/instance attributes.
deep_getattr function¶
Retrieve attribute consecutively.
The attribute chain attr_chain can be:
- string -> get variable/property or method without arguments
- tuple of string -> call method without arguments
- tuple of string and tuple -> call method and pass positional arguments (unpacked)
- tuple of string, tuple, and dict -> call method and pass positional and keyword arguments (unpacked)
- iterable of any of the above
Use getattr_func to overwrite the default behavior of accessing an attribute (see default_getattr_func()).
Hint
If your chain includes only attributes and functions without arguments, you can represent this chain as a single (but probably long) string.
default_getattr_func function¶
Default getattr_func.
get_dict_attr function¶
Get attribute without invoking the attribute lookup machinery.
parse_attrs function¶
Parse attributes of a class, object, or a module, and return a DataFrame with types and paths.
AttrResolverMixin class¶
Class that implements resolution of self and its attributes.
Resolution is getattr that works for self, properties, and methods. It also utilizes built-in caching.
Subclasses
cls_dir method¶
Get set of attribute names.
deep_getattr method¶
See deep_getattr().
post_resolve_attr method¶
Post-process an object after resolution.
Must return an object.
pre_resolve_attr method¶
Pre-process an attribute before resolution.
Must return an attribute.
resolve_attr method¶
AttrResolverMixin.resolve_attr(
attr,
args=None,
cond_kwargs=None,
kwargs=None,
custom_arg_names=None,
cache_dct=None,
use_caching=True,
passed_kwargs_out=None,
use_shortcuts=True
)
Resolve an attribute using keyword arguments and built-in caching.
- If there is a
get_{arg}method, usesget_{arg}asattr. - If
attris a property, returns its value. - If
attris a method, passes*args,**kwargs, and**cond_kwargswith keys found in the signature. - If
use_shortcutsis True, resolves the potential shortcuts using AttrResolverMixin.resolve_shortcut_attr().
Won't cache if use_caching is False or any passed argument is in custom_arg_names.
Use passed_kwargs_out to get keyword arguments that were passed.
resolve_self method¶
AttrResolverMixin.resolve_self(
cond_kwargs=None,
custom_arg_names=None,
impacts_caching=True,
silence_warnings=False
)
Resolve self.
Note
cond_kwargs can be modified in-place.
resolve_shortcut_attr method¶
Resolve an attribute that may have shortcut properties.
self_aliases property¶
Names to associate with this object.