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

Method _get_optional_kwargs

Lib/argparse.py:1658–1688  ·  view source on GitHub ↗
(self, *args, **kwargs)

Source from the content-addressed store, hash-verified

1656 return dict(kwargs, dest=dest, option_strings=[])
1657
1658 def _get_optional_kwargs(self, *args, **kwargs):
1659 # determine short and long option strings
1660 option_strings = []
1661 long_option_strings = []
1662 for option_string in args:
1663 # error on strings that don't start with an appropriate prefix
1664 if not option_string[0] in self.prefix_chars:
1665 raise ValueError(
1666 f'invalid option string {option_string!r}: '
1667 f'must start with a character {self.prefix_chars!r}')
1668
1669 # strings starting with two prefix characters are long options
1670 option_strings.append(option_string)
1671 if len(option_string) > 1 and option_string[1] in self.prefix_chars:
1672 long_option_strings.append(option_string)
1673
1674 # infer destination, '--foo-bar' -> 'foo_bar' and '-x' -> 'x'
1675 dest = kwargs.pop('dest', None)
1676 if dest is None:
1677 if long_option_strings:
1678 dest_option_string = long_option_strings[0]
1679 else:
1680 dest_option_string = option_strings[0]
1681 dest = dest_option_string.lstrip(self.prefix_chars)
1682 if not dest:
1683 msg = f'dest= is required for options like {option_string!r}'
1684 raise TypeError(msg)
1685 dest = dest.replace('-', '_')
1686
1687 # return the updated keyword arguments
1688 return dict(kwargs, dest=dest, option_strings=option_strings)
1689
1690 def _pop_action_class(self, kwargs, default=None):
1691 action = kwargs.pop('action', default)

Callers 1

add_argumentMethod · 0.95

Calls 5

lenFunction · 0.85
appendMethod · 0.45
popMethod · 0.45
lstripMethod · 0.45
replaceMethod · 0.45

Tested by

no test coverage detected