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

Axel report at bugs.python.org
Fri Feb 22 09:18:34 EST 2019


New submission from Axel <pyd at jejajo.de>:

Example source:
from argparse import ArgumentParser, SUPPRESS
==============
parser = ArgumentParser()
parser.add_argument('i', nargs='?', type=int, default=SUPPRESS)
args = parser.parse_args([])
==============
results in:
error: argument integer: invalid int value: '==SUPPRESS=='

Expected: args = Namespace()


In Lib/argparse.py:
line 2399 in _get_value: result = type_func(arg_string)
with arg_string = SUPPRESS = '==SUPPRESS=='

called by ... line 1836 in take_action: argument_values = self._get_values(action, argument_strings)
which is done before checking for SUPPRESS in line 1851:
    if argument_values is not SUPPRESS:
       action(...)

----------
components: Library (Lib)
messages: 336314
nosy: n8falke
priority: normal
severity: normal
status: open
title: argparse: positional with type=int, default=SUPPRESS raise ValueError
type: behavior
versions: Python 3.8

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


More information about the Python-bugs-list mailing list