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

Method _get_optional_kwargs

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

Source from the content-addressed store, hash-verified

1732 return dict(kwargs, dest=dest, option_strings=[])
1733
1734 def _get_optional_kwargs(self, *args, **kwargs):
1735 # determine short and long option strings
1736 option_strings = []
1737 for option_string in args:
1738 # error on strings that don't start with an appropriate prefix
1739 if option_string[0] not in self.prefix_chars:
1740 raise ValueError(
1741 f'invalid option string {option_string!r}: '
1742 f'must start with a character {self.prefix_chars!r}')
1743 option_strings.append(option_string)
1744
1745 # infer destination, '--foo-bar' -> 'foo_bar' and '-x' -> 'x'
1746 dest = kwargs.pop('dest', None)
1747 if dest is None:
1748 priority = 0
1749 for option_string in option_strings:
1750 if len(option_string) <= 2:
1751 # short option: '-x' -> 'x'
1752 if priority < 1:
1753 dest = option_string.lstrip(self.prefix_chars)
1754 priority = 1
1755 elif option_string[1] not in self.prefix_chars:
1756 # single-dash long option: '-foo' -> 'foo'
1757 if priority < 2:
1758 dest = option_string.lstrip(self.prefix_chars)
1759 priority = 2
1760 else:
1761 # two-dash long option: '--foo' -> 'foo'
1762 dest = option_string.lstrip(self.prefix_chars)
1763 break
1764 if not dest:
1765 msg = f'dest= is required for options like {repr(option_strings)[1:-1]}'
1766 raise TypeError(msg)
1767 dest = dest.replace('-', '_')
1768
1769 # return the updated keyword arguments
1770 return dict(kwargs, dest=dest, option_strings=option_strings)
1771
1772 def _pop_action_class(self, kwargs, default=None):
1773 action = kwargs.pop('action', default)

Callers 1

add_argumentMethod · 0.95

Calls 4

appendMethod · 0.45
popMethod · 0.45
lstripMethod · 0.45
replaceMethod · 0.45

Tested by

no test coverage detected