Skip to content

bpo-40509: Enable REMAINDER argparse arguments to be used in mutually exclusive … #19919

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Lib/argparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -1516,7 +1516,7 @@ def _get_positional_kwargs(self, dest, **kwargs):

# mark positional arguments as required if at least one is
# always required
if kwargs.get('nargs') not in [OPTIONAL, ZERO_OR_MORE]:
if kwargs.get('nargs') not in [OPTIONAL, ZERO_OR_MORE, REMAINDER]:
kwargs['required'] = True
if kwargs.get('nargs') == ZERO_OR_MORE and 'default' not in kwargs:
kwargs['required'] = True
Expand Down Expand Up @@ -1915,6 +1915,10 @@ def take_action(action, argument_strings, option_string=None):
# error if this argument is not allowed with other previously
# seen arguments, assuming that actions that use the default
# value don't really count as "present"
if action.nargs in [REMAINDER]:
if argument_values == []:
action.default = argument_values

if argument_values is not action.default:
seen_non_default_actions.add(action)
for conflict_action in action_conflicts.get(action, []):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Allow REMAINDER positional arguments in argparse mutually exclusive groups.