attr_ module¶
Utilities for working with class/instance attributes.
MISSING Missing { #vectorbtpro.utils.attr.MISSING data-toc-label='MISSING' }¶
Sentinel that represents a missing value.
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.
DefineMixin class¶
Mixin class for define.
Superclasses
Inherited members
Subclasses
- ArgGetter
- ArgSizer
- AutoIdxr
- AxisSpecifier
- BCO
- CABaseSetup
- CAClassSetup
- CAInstanceSetup
- CAQuery
- CARule
- CARunResult
- CARunSetup
- CAUnboundSetup
- ChunkMapper
- ChunkMeta
- ChunkSelector
- ChunkTaker
- Chunked
- ChunkedArray
- ChunkedSetup
- ColIdxr
- ContainerTaker
- CustomTemplate
- DTC
- DTCIdxr
- DatetimeIdxr
- Default
- DimRetainer
- ExceptLevel
- FixRange
- FlexArraySelector
- FlexArraySlicer
- GroupIdxsMapper
- GroupLensMapper
- IdxDict
- IdxFrame
- IdxRecords
- IdxSeries
- IdxSetter
- Idxr
- JitableSetup
- JittedSetup
- LabelIdxr
- LabelSel
- MaskIdxr
- MergeFunc
- NotChunked
- PSC
- Param
- PointIdxr
- PosIdxr
- PosSel
- RangeIdxr
- RecInfo
- RecState
- Ref
- Regex
- RelRange
- RowIdxr
- ShapeSelector
- ShapeSizer
- ShapeSlicer
- Takeable
- Task
- UniIdxrOp
- Union
- VarArgs
- VarKwargs
- hslice
asdict method¶
Convert this instance to a dictionary.
If full is False, won't include fields with MISSING as value.
assert_field_not_missing method¶
Raise an error if a field is missing.
fields class variable¶
fields_dict class variable¶
get_field class method¶
Get field.
is_field_missing method¶
Raise an error if a field is missing.
is_field_optional class method¶
Return whether a field is optional.
is_field_required class method¶
Return whether a field is required.
merge_over method¶
Merge this instance over another instance.
merge_with method¶
Merge this instance with another instance.
replace method¶
Create a new instance by making changes to the attribute values.
resolve method¶
Resolve a field or all fields.
resolve_field method¶
Resolve a field.
define class¶
Prepare a class decorated with define.
Attaches DefineMixin as a base class (if not present) and applies attr.define.
field class method¶
Alias for attr.field.
optional_field class method¶
Alias for attr.field with MISSING as default.
Has default in metadata.
required_field class method¶
Alias for attr.field with MISSING as default.
Doesn't have default in metadata.