[New-bugs-announce] [issue40615] argparse

gaborbernat report at bugs.python.org
Wed May 13 07:49:46 EDT 2020


New submission from gaborbernat <gaborjbernat at gmail.com>:

Consider the following code:

from argparse import ArgumentParser

parser = ArgumentParser()
parser.add_argument("--clear-magic", action="store_true")
print(parser.parse_args(["--clear"]))

parser.add_argument("--clear", action="store_true")
print(parser.parse_args(["--clear"]))

This has the following output:

Namespace(clear_magic=True)
Namespace(clear=True, clear_magic=False)

I find it surprising and confusing why the clear magic option is accepted when clear is not defined. I'm tempted to say it's a bug. This unstable behaviour is very surprising when iteratively building up the parser.  

Discovered with https://github.com/pypa/virtualenv/issues/1824#issuecomment-627919033

----------
messages: 368776
nosy: gaborbernat
priority: normal
severity: normal
status: open
title: argparse

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


More information about the New-bugs-announce mailing list