MCPcopy
hub / github.com/google/python-fire / _GetMember

Function _GetMember

fire/core.py:622–649  ·  view source on GitHub ↗

Returns a subcomponent of component by consuming an arg from args. Given a starting component and args, this function gets a member from that component, consuming one arg in the process. Args: component: The component from which to get a member. args: Args from which to consume in th

(component, args)

Source from the content-addressed store, hash-verified

620
621
622def _GetMember(component, args):
623 """Returns a subcomponent of component by consuming an arg from args.
624
625 Given a starting component and args, this function gets a member from that
626 component, consuming one arg in the process.
627
628 Args:
629 component: The component from which to get a member.
630 args: Args from which to consume in the search for the next component.
631 Returns:
632 component: The component that was found by consuming an arg.
633 consumed_args: The args that were consumed by getting this member.
634 remaining_args: The remaining args that haven't been consumed yet.
635 Raises:
636 FireError: If we cannot consume an argument to get a member.
637 """
638 members = dir(component)
639 arg = args[0]
640 arg_names = [
641 arg,
642 arg.replace('-', '_'), # treat '-' as '_'.
643 ]
644
645 for arg_name in arg_names:
646 if arg_name in members:
647 return getattr(component, arg_name), [arg], args[1:]
648
649 raise FireError('Could not consume arg:', arg)
650
651
652def _CallAndUpdateTrace(component, args, component_trace, treatment='class',

Callers 1

_FireFunction · 0.85

Calls 1

FireErrorClass · 0.85

Tested by

no test coverage detected