This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author paul.j3
Recipients ajstewart, paul.j3, wolma
Date 2017-07-27.23:13:27
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
The problem described here is restricted to `?` and `*' positionals, and is caused by the subtle way in which 'empty' optional positionals are handled.

The regular handling of defaults at the start of `parse_known_args` works fine.  The default is only written to the namespace if something isn't there already.

     if not hasattr(namespace, action.dest):
         if action.default is not SUPPRESS:
              setattr(namespace, action.dest, action.default)

But a positional with ? or * is always 'seen' because an empty list of strings satisfies the nargs pattern.  'get_values()' has special handling for this case:

        if not arg_strings and action.nargs == OPTIONAL:
                value = action.default

That is, it replaces the empty list with the 'default'. 

But take_action(), which does the actual saving, is conditional:

            # take the action if we didn't receive a SUPPRESS value
            # (e.g. from a default)
            if argument_values is not SUPPRESS:
                action(self, namespace, argument_values, option_string)

That explains why 'default=SUPPRESS' solves this issue.

It's enough to satisfy the OP's situation, but I don't think it's a robust fix.

I don't have a patch idea yet, but this probably should be reopened so there's a record of the potential problem.

More on the complications raised by these 'seen default actions' in
Date User Action Args
2017-07-27 23:13:28paul.j3setrecipients: + paul.j3, wolma, ajstewart
2017-07-27 23:13:28paul.j3setmessageid: <>
2017-07-27 23:13:28paul.j3linkissue28734 messages
2017-07-27 23:13:27paul.j3create