[issue40303] argparse parse_args args parameter bug or intended

2020-04-16 Thread Gharg


New submission from Gharg :

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 
<https://bugs.python.org/issue40303>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40303] argparse parse_args args parameter bug or intended

2020-04-17 Thread Gharg

Gharg  added the comment:

Hi Rémi and Paul,

thanks for your quick response.
It is as i expected and i will use 'store_true'/'store_false' to resolve my 
problem.

I see this issue as resolved and close it.

--
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

___
Python tracker 
<https://bugs.python.org/issue40303>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com