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

Method _match_argument

Lib/argparse.py:2472–2492  ·  view source on GitHub ↗
(self, action, arg_strings_pattern)

Source from the content-addressed store, hash-verified

2470 return [arg_line]
2471
2472 def _match_argument(self, action, arg_strings_pattern):
2473 # match the pattern for this action to the arg strings
2474 nargs_pattern = self._get_nargs_pattern(action)
2475 match = _re.match(nargs_pattern, arg_strings_pattern)
2476
2477 # raise an exception if we weren't able to find a match
2478 if match is None:
2479 nargs_errors = {
2480 None: _('expected one argument'),
2481 OPTIONAL: _('expected at most one argument'),
2482 ONE_OR_MORE: _('expected at least one argument'),
2483 }
2484 msg = nargs_errors.get(action.nargs)
2485 if msg is None:
2486 msg = ngettext('expected %s argument',
2487 'expected %s arguments',
2488 action.nargs) % action.nargs
2489 raise ArgumentError(action, msg)
2490
2491 # return the number of arguments matched
2492 return len(match.group(1))
2493
2494 def _match_arguments_partial(self, actions, arg_strings_pattern):
2495 # progressively shorten the actions list by slicing off the

Callers

nothing calls this directly

Calls 7

_get_nargs_patternMethod · 0.95
ngettextFunction · 0.90
ArgumentErrorClass · 0.70
_Function · 0.50
matchMethod · 0.45
getMethod · 0.45
groupMethod · 0.45

Tested by

no test coverage detected