Skip to content

Commit 89386f8

Browse files
committed
nested_callable
1 parent d66eadf commit 89386f8

File tree

5 files changed

+286
-228
lines changed

5 files changed

+286
-228
lines changed

fastcore/_nbdev.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
"renumerate": "01_basics.ipynb",
9393
"first": "01_basics.ipynb",
9494
"nested_attr": "01_basics.ipynb",
95+
"nested_callable": "01_basics.ipynb",
9596
"nested_idx": "01_basics.ipynb",
9697
"set_nested_idx": "01_basics.ipynb",
9798
"val2idx": "01_basics.ipynb",

fastcore/basics.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
'GetAttrBase', 'GetAttr', 'delegate_attr', 'ShowPrint', 'Int', 'Str', 'Float', 'flatten', 'concat', 'strcat',
1010
'detuplify', 'replicate', 'setify', 'merge', 'range_of', 'groupby', 'last_index', 'filter_dict',
1111
'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']
12+
'range_of', 'renumerate', 'first', 'nested_attr', 'nested_callable', 'nested_idx', 'set_nested_idx',
13+
'val2idx', 'uniqueify', 'loop_first_last', 'loop_first', 'loop_last', 'num_methods', 'rnum_methods',
14+
'inum_methods', 'fastuple', 'arg0', 'arg1', 'arg2', 'arg3', 'arg4', 'bind', 'mapt', 'map_ex', 'compose',
15+
'maps', 'partialler', 'instantiate', 'using_attr', 'Self', 'Self', 'copy_func', 'patch_to', 'patch',
16+
'patch_property', 'compile_re', 'ImportEnum', 'StrEnum', 'str_enum', 'Stateful', 'PrettyString',
17+
'even_mults', 'num_cpus', 'add_props', 'typed', 'exec_new', 'exec_import']
1818

1919
# Cell
2020
from .imports import *
@@ -628,6 +628,11 @@ def nested_attr(o, attr, default=None):
628628
except AttributeError: return default
629629
return o
630630

631+
# Cell
632+
def nested_callable(o, attr):
633+
"Same as `nested_attr` but if not found will return `noop`"
634+
return nested_attr(o, attr, noop)
635+
631636
# Cell
632637
def _access(coll, idx): return coll.get(idx, None) if hasattr(coll, 'get') else coll[idx] if idx<len(coll) else None
633638

fastcore/transform.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def _call1(self, x, name, **kwargs):
122122
# Cell
123123
def get_func(t, name, *args, **kwargs):
124124
"Get the `t.name` (potentially partial-ized with `args` and `kwargs`) or `noop` if not defined"
125-
f = getattr(t, name, noop)
125+
f = nested_callable(t, name)
126126
return f if not (args or kwargs) else partial(f, *args, **kwargs)
127127

128128
# Cell

0 commit comments

Comments
 (0)