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

Method _expand_help

Lib/argparse.py:682–729  ·  view source on GitHub ↗
(self, action)

Source from the content-addressed store, hash-verified

680 return result
681
682 def _expand_help(self, action):
683 help_string = self._get_help_string(action)
684 if '%' not in help_string:
685 return help_string
686 params = dict(vars(action), prog=self._prog)
687 for name in list(params):
688 value = params[name]
689 if value is SUPPRESS:
690 del params[name]
691 elif hasattr(value, '__name__'):
692 params[name] = value.__name__
693 if params.get('choices') is not None:
694 params['choices'] = ', '.join(map(str, params['choices']))
695
696 t = self._theme
697
698 result = help_string % params
699
700 if not t.reset:
701 return result
702
703 # Match format specifiers like: %s, %d, %(key)s, etc.
704 fmt_spec = r'''
705 %
706 (?:
707 % # %% escape
708 |
709 (?:\((?P<key>[^)]*)\))? # key
710 [-#0\ +]* # flags
711 (?:\*|\d+)? # width
712 (?:\.(?:\*|\d+))? # precision
713 [hlL]? # length modifier
714 [diouxXeEfFgGcrsa] # conversion type
715 )
716 ''&#x27;
717
718 def colorize(match):
719 spec, key = match.group(0, 'key')
720 if spec == '%%':
721 return '%'
722 if key is not None:
723 # %(key)... - format and colorize
724 formatted = spec % {key: params[key]}
725 return f'{t.interpolated_value}{formatted}{t.reset}'
726 # bare %s etc. - format with full params dict, no colorization
727 return spec % params
728
729 return _re.sub(fmt_spec, colorize, help_string, flags=_re.VERBOSE)
730
731 def _iter_indented_subactions(self, action):
732 try:

Callers 2

_format_actionMethod · 0.95
_check_helpMethod · 0.80

Calls 5

_get_help_stringMethod · 0.95
listClass · 0.85
getMethod · 0.45
joinMethod · 0.45
subMethod · 0.45

Tested by

no test coverage detected