bpo-29298: Fix crash with required subparsers without dest by asottile · Pull Request #3680 · python/cpython (original) (raw)
Code for this is already in _metavar_formatter
:
elif action.choices is not None:
choice_strs = [str(choice) for choice in action.choices]
result = '{%s}' % ','.join(choice_strs)
The metavar formatter can be called, if the parser is known (as self
), using:
default = self._get_default_metavar_for_positional(action)
metavar, = self._metavar_formatter(action, default)(1)
Perhaps _get_action_name
should be made into a method, or take the parser as an optional argument?