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

Method _get_actions_usage_parts

Lib/argparse.py:410–514  ·  view source on GitHub ↗

Get usage parts with split index for optionals/positionals. Returns (parts, pos_start) where pos_start is the index in parts where positionals begin. This preserves mutually exclusive group formatting across the optionals/positionals boundary (gh-75949).

(self, actions, groups)

Source from the content-addressed store, hash-verified

408 return len(string) > 2
409
410 def _get_actions_usage_parts(self, actions, groups):
411 """Get usage parts with split index for optionals/positionals.
412
413 Returns (parts, pos_start) where pos_start is the index in parts
414 where positionals begin.
415 This preserves mutually exclusive group formatting across the
416 optionals/positionals boundary (gh-75949).
417 """
418 actions = [action for action in actions if action.help is not SUPPRESS]
419 # group actions by mutually exclusive groups
420 action_groups = dict.fromkeys(actions)
421 for group in groups:
422 for action in group._group_actions:
423 if action in action_groups:
424 action_groups[action] = group
425 # positional arguments keep their position
426 positionals = []
427 for action in actions:
428 if not action.option_strings:
429 group = action_groups.pop(action)
430 if group:
431 group_actions = [
432 action2 for action2 in group._group_actions
433 if action2.option_strings and
434 action_groups.pop(action2, None)
435 ] + [action]
436 positionals.append((group.required, group_actions))
437 else:
438 positionals.append((None, [action]))
439 # the remaining optional arguments are sorted by the position of
440 # the first option in the group
441 optionals = []
442 for action in actions:
443 if action.option_strings and action in action_groups:
444 group = action_groups.pop(action)
445 if group:
446 group_actions = [action] + [
447 action2 for action2 in group._group_actions
448 if action2.option_strings and
449 action_groups.pop(action2, None)
450 ]
451 optionals.append((group.required, group_actions))
452 else:
453 optionals.append((None, [action]))
454
455 # collect all actions format strings
456 parts = []
457 t = self._theme
458 pos_start = None
459 for i, (required, group) in enumerate(optionals + positionals):
460 start = len(parts)
461 if i == len(optionals):
462 pos_start = start
463 in_group = len(group) > 1
464 for action in group:
465 # produce all arg strings
466 if not action.option_strings:
467 default = self._get_default_metavar_for_positional(action)

Callers 1

_format_usageMethod · 0.95

Calls 10

_format_argsMethod · 0.95
_is_long_optionMethod · 0.95
enumerateFunction · 0.85
lenFunction · 0.85
fromkeysMethod · 0.45
popMethod · 0.45
appendMethod · 0.45
format_usageMethod · 0.45

Tested by

no test coverage detected