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

Axel report at bugs.python.org
Fri Feb 22 10:03:54 EST 2019


Axel <pyd at jejajo.de> added the comment:

Some more details:
The problem is not the order of assignment in take_action:
Defaults have been set by:
    def parse_known_args(self, args=None, namespace=None):
        ...
        # add any action defaults that aren't present
        for action in self._actions:
            if action.dest is not SUPPRESS:
                if not hasattr(namespace, action.dest):
                    if action.default is not SUPPRESS:
                        setattr(namespace, action.dest, action.default)

Assignment without argument should not happen, like the example shows:
==============
from argparse import ArgumentParser
parser = ArgumentParser()
parser.add_argument('i', action="count", default=42)
args = parser.parse_args([])
print(repr(args))
==============
Namespace(i=43)
==============

----------
nosy:  -paul.j3

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


More information about the Python-bugs-list mailing list