|
5 | 5 | 'Inf', 'in_', 'lt', 'gt', 'le', 'ge', 'eq', 'ne', 'add', 'sub', 'mul', 'truediv', 'is_', 'is_not', 'in_',
|
6 | 6 | 'true', 'stop', 'gen', 'chunked', 'otherwise', 'custom_dir', 'AttrDict', 'get_annotations_ex', 'eval_type',
|
7 | 7 | 'type_hints', 'annotations', 'anno_ret', 'argnames', 'with_cast', 'store_attr', 'attrdict', 'properties',
|
8 |
| - 'camel2words', 'camel2snake', 'snake2camel', 'class2attr', 'getattrs', 'hasattrs', 'setattrs', 'try_attrs', |
9 |
| - 'GetAttrBase', 'GetAttr', 'delegate_attr', 'ShowPrint', 'Int', 'Str', 'Float', 'flatten', 'concat', 'strcat', |
10 |
| - 'detuplify', 'replicate', 'setify', 'merge', 'range_of', 'groupby', 'last_index', 'filter_dict', |
11 |
| - 'filter_keys', 'filter_values', 'cycle', 'zip_cycle', 'sorted_ex', 'not_', 'argwhere', 'filter_ex', |
12 |
| - 'range_of', 'renumerate', 'first', 'nested_attr', 'nested_idx', 'set_nested_idx', 'val2idx', 'uniqueify', |
13 |
| - 'loop_first_last', 'loop_first', 'loop_last', 'num_methods', 'rnum_methods', 'inum_methods', 'fastuple', |
14 |
| - 'arg0', 'arg1', 'arg2', 'arg3', 'arg4', 'bind', 'mapt', 'map_ex', 'compose', 'maps', 'partialler', |
15 |
| - 'instantiate', 'using_attr', 'Self', 'Self', 'copy_func', 'patch_to', 'patch', 'patch_property', |
16 |
| - 'compile_re', 'ImportEnum', 'StrEnum', 'str_enum', 'Stateful', 'PrettyString', 'even_mults', 'num_cpus', |
17 |
| - 'add_props', 'typed', 'exec_new', 'exec_import'] |
| 8 | + 'camel2words', 'camel2snake', 'snake2camel', 'class2attr', 'getcallable', 'getattrs', 'hasattrs', 'setattrs', |
| 9 | + 'try_attrs', 'GetAttrBase', 'GetAttr', 'delegate_attr', 'ShowPrint', 'Int', 'Str', 'Float', 'flatten', |
| 10 | + 'concat', 'strcat', 'detuplify', 'replicate', 'setify', 'merge', 'range_of', 'groupby', 'last_index', |
| 11 | + 'filter_dict', 'filter_keys', 'filter_values', 'cycle', 'zip_cycle', 'sorted_ex', 'not_', 'argwhere', |
| 12 | + 'filter_ex', 'range_of', 'renumerate', 'first', 'nested_attr', 'nested_callable', 'nested_idx', |
| 13 | + 'set_nested_idx', 'val2idx', 'uniqueify', 'loop_first_last', 'loop_first', 'loop_last', 'num_methods', |
| 14 | + 'rnum_methods', 'inum_methods', 'fastuple', 'arg0', 'arg1', 'arg2', 'arg3', 'arg4', 'bind', 'mapt', 'map_ex', |
| 15 | + 'compose', 'maps', 'partialler', 'instantiate', 'using_attr', 'Self', 'Self', 'copy_func', 'patch_to', |
| 16 | + 'patch', 'patch_property', 'compile_re', 'ImportEnum', 'StrEnum', 'str_enum', 'Stateful', 'PrettyString', |
| 17 | + 'even_mults', 'num_cpus', 'add_props', 'typed', 'exec_new', 'exec_import'] |
18 | 18 |
|
19 | 19 | # Cell
|
20 | 20 | from .imports import *
|
@@ -406,6 +406,11 @@ def class2attr(self, cls_name):
|
406 | 406 | "Return the snake-cased name of the class; strip ending `cls_name` if it exists."
|
407 | 407 | return camel2snake(re.sub(rf'{cls_name}$', '', self.__class__.__name__) or cls_name.lower())
|
408 | 408 |
|
| 409 | +# Cell |
| 410 | +def getcallable(o, attr): |
| 411 | + "Calls `getattr` with a default of `noop`" |
| 412 | + return getattr(o, attr, noop) |
| 413 | + |
409 | 414 | # Cell
|
410 | 415 | def getattrs(o, *attrs, default=None):
|
411 | 416 | "List of all `attrs` in `o`"
|
@@ -628,6 +633,11 @@ def nested_attr(o, attr, default=None):
|
628 | 633 | except AttributeError: return default
|
629 | 634 | return o
|
630 | 635 |
|
| 636 | +# Cell |
| 637 | +def nested_callable(o, attr): |
| 638 | + "Same as `nested_attr` but if not found will return `noop`" |
| 639 | + return nested_attr(o, attr, noop) |
| 640 | + |
631 | 641 | # Cell
|
632 | 642 | def _access(coll, idx): return coll.get(idx, None) if hasattr(coll, 'get') else coll[idx] if idx<len(coll) else None
|
633 | 643 |
|
|
0 commit comments