for verb in ('setattr', 'do', 'doafter'):
for task, args in [t for t in ret['_tasks'].items()
if t[0].verb == verb]:
- path = list(task.path)
- node: Any = (ret[path.pop(0)[1]]
- if task.path and path[0][1].isupper() else self)
- for is_dict_key, step_name in path:
- if is_dict_key:
- if step_name.isupper():
- step_name = ret[step_name]
- node = node[step_name]
- else:
- node = (node(step_name) if callable(node)
- else getattr(node, step_name))
+ node: Any = self
+ for idx, step_t in enumerate(task.path):
+ is_dict_key, step_code = step_t
+ step = ret[step_code] if step_code.isupper() else step_code
+ if idx == 0 and not isinstance(step, str):
+ node = step
+ continue
+ node = (node[step] if is_dict_key
+ else (node(step) if callable(node)
+ else getattr(node, step)))
for arg in args:
if task.verb == 'setattr':
setattr(node, arg, ret[arg])