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

Method _get_option_tuples

Lib/argparse.py:2557–2599  ·  view source on GitHub ↗
(self, option_string)

Source from the content-addressed store, hash-verified

2555 return [(None, arg_string, None, None)]
2556
2557 def _get_option_tuples(self, option_string):
2558 result = []
2559
2560 # option strings starting with two prefix characters are only
2561 # split at the '='
2562 chars = self.prefix_chars
2563 if option_string[0] in chars and option_string[1] in chars:
2564 if self.allow_abbrev:
2565 option_prefix, sep, explicit_arg = option_string.partition('=')
2566 if not sep:
2567 sep = explicit_arg = None
2568 for option_string in self._option_string_actions:
2569 if option_string.startswith(option_prefix):
2570 action = self._option_string_actions[option_string]
2571 tup = action, option_string, sep, explicit_arg
2572 result.append(tup)
2573
2574 # single character options can be concatenated with their arguments
2575 # but multiple character options always have to have their argument
2576 # separate
2577 elif option_string[0] in chars and option_string[1] not in chars:
2578 option_prefix, sep, explicit_arg = option_string.partition('=')
2579 if not sep:
2580 sep = explicit_arg = None
2581 short_option_prefix = option_string[:2]
2582 short_explicit_arg = option_string[2:]
2583
2584 for option_string in self._option_string_actions:
2585 if option_string == short_option_prefix:
2586 action = self._option_string_actions[option_string]
2587 tup = action, option_string, '', short_explicit_arg
2588 result.append(tup)
2589 elif self.allow_abbrev and option_string.startswith(option_prefix):
2590 action = self._option_string_actions[option_string]
2591 tup = action, option_string, sep, explicit_arg
2592 result.append(tup)
2593
2594 # shouldn't ever get here
2595 else:
2596 raise ArgumentError(None, _('unexpected option string: %s') % option_string)
2597
2598 # return the collected option tuples
2599 return result
2600
2601 def _get_nargs_pattern(self, action):
2602 # in all examples below, we have to allow for '--' args

Callers 1

_parse_optionalMethod · 0.95

Calls 5

ArgumentErrorClass · 0.70
_Function · 0.50
partitionMethod · 0.45
startswithMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected