MCPcopy Index your code
hub / github.com/python/cpython / _get_values

Method _get_values

Lib/argparse.py:2679–2724  ·  view source on GitHub ↗
(self, action, arg_strings)

Source from the content-addressed store, hash-verified

2677 # ========================
2678
2679 def _get_values(self, action, arg_strings):
2680 # optional argument produces a default when not present
2681 if not arg_strings and action.nargs == OPTIONAL:
2682 if action.option_strings:
2683 value = action.const
2684 else:
2685 value = action.default
2686 if isinstance(value, str) and value is not SUPPRESS:
2687 value = self._get_value(action, value)
2688
2689 # when nargs='*' on a positional, if there were no command-line
2690 # args, use the default if it is anything other than None
2691 elif (not arg_strings and action.nargs == ZERO_OR_MORE and
2692 not action.option_strings):
2693 if action.default is not None:
2694 value = action.default
2695 else:
2696 value = []
2697
2698 # single argument or optional argument produces a single value
2699 elif len(arg_strings) == 1 and action.nargs in [None, OPTIONAL]:
2700 arg_string, = arg_strings
2701 value = self._get_value(action, arg_string)
2702 self._check_value(action, value)
2703
2704 # REMAINDER arguments convert all values, checking none
2705 elif action.nargs == REMAINDER:
2706 value = [self._get_value(action, v) for v in arg_strings]
2707
2708 # PARSER arguments convert all values, but check only the first
2709 elif action.nargs == PARSER:
2710 value = [self._get_value(action, v) for v in arg_strings]
2711 self._check_value(action, value[0])
2712
2713 # SUPPRESS argument does not put anything in the namespace
2714 elif action.nargs == SUPPRESS:
2715 value = SUPPRESS
2716
2717 # all other types of nargs produce a list
2718 else:
2719 value = [self._get_value(action, v) for v in arg_strings]
2720 for v in value:
2721 self._check_value(action, v)
2722
2723 # return the converted value
2724 return value
2725
2726 def _get_value(self, action, arg_string):
2727 type_func = self._registry_get('type', action.type, action.type)

Callers 1

take_actionMethod · 0.95

Calls 2

_get_valueMethod · 0.95
_check_valueMethod · 0.95

Tested by

no test coverage detected