MCPcopy Index your code
hub / github.com/RustPython/RustPython / _match_argument

Method _match_argument

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

Source from the content-addressed store, hash-verified

2388 return [arg_line]
2389
2390 def _match_argument(self, action, arg_strings_pattern):
2391 # match the pattern for this action to the arg strings
2392 nargs_pattern = self._get_nargs_pattern(action)
2393 match = _re.match(nargs_pattern, arg_strings_pattern)
2394
2395 # raise an exception if we weren't able to find a match
2396 if match is None:
2397 nargs_errors = {
2398 None: _('expected one argument'),
2399 OPTIONAL: _('expected at most one argument'),
2400 ONE_OR_MORE: _('expected at least one argument'),
2401 }
2402 msg = nargs_errors.get(action.nargs)
2403 if msg is None:
2404 msg = ngettext('expected %s argument',
2405 'expected %s arguments',
2406 action.nargs) % action.nargs
2407 raise ArgumentError(action, msg)
2408
2409 # return the number of arguments matched
2410 return len(match.group(1))
2411
2412 def _match_arguments_partial(self, actions, arg_strings_pattern):
2413 # progressively shorten the actions list by slicing off the

Callers

nothing calls this directly

Calls 8

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

Tested by

no test coverage detected