[New-bugs-announce] [issue40303] argparse parse_args args parameter bug or intended

Gharg report at bugs.python.org
Thu Apr 16 12:47:14 EDT 2020


New submission from Gharg <ghaarg at gmail.com>:

I have a problem regarding args parameter of ArgumentParser.parse_args.

For example:
-------------------------------------
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("--boolean", type=bool)
parsed_args = parser.parse_args(["--boolean=''"])
--------------------------------------

results in parsed_args.boolean evaluate to True.
While i understand why this is happening (inner call of bool("''") evaluates to True), i don't know if that is an expected behavior.
If we look from console argument pass perspective with the example altered:
test.py
-------------------------------------
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("--boolean", type=bool)
parsed_args = parser.parse_args()
--------------------------------------

If i now call:

python test.py --boolean=""

parsed_args.boolean will evaluate to False.

----------
messages: 366608
nosy: Gharg
priority: normal
severity: normal
status: open
title: argparse parse_args args parameter bug or intended
type: behavior
versions: Python 3.7

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


More information about the New-bugs-announce mailing list