[issue36078] argparse: positional with type=int, default=SUPPRESS raise ValueError

paul j3 report at bugs.python.org
Fri Feb 22 12:57:05 EST 2019


paul j3 <ajipanca at gmail.com> added the comment:

Defaults are handled into two stages.

At the start of parsing defaults are added to the Namespace.

At the end of parsing intact defaults are evaluated with 'type'.

But a nargs='?' positional gets special handling.  It matches an empty string, so it is always 'seen'.  If its default is not None, that default is put in the Namespace instead of the matching empty list.

It's this special default handling that lets us use a ?-positional in a mutually exclusive group.

I suspect the error arises from this special default handling, but I'll have to look at the code to verify the details.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue36078>
_______________________________________


More information about the Python-bugs-list mailing list