Issue 36358: bool type does not support True or False as command line argv

Issue36358

Created on 2019-03-19 06:56 by Abhinav Gupta, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (2)
msg338321 - (view) Author: Abhinav Gupta (Abhinav Gupta) Date: 2019-03-19 06:56
If I have a type=bool argument in argparser and I provide the value for it using command-line, it always evaluates to True. Is this expected?

Is there no alternative to using '' for False and any other string for True?
msg338323 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2019-03-19 07:40
Yes, this is expected. bool('False') is True.

You can write your own converter which returns True for 'True', False for 'False' and raise an exception otherwise.

But it is more common to add a pair of options without arguments --foo/--no-foo, or --with-foo/--without-foo, or --enable-foo/--disable-foo using the "store_const" action with True/False value.
History
Date User Action Args
2022-04-11 14:59:12adminsetgithub: 80539
2019-03-19 07:40:39serhiy.storchakasetstatus: open -> closed

nosy: + serhiy.storchaka
messages: + msg338323

resolution: not a bug
stage: resolved

2019-03-19 06:56:39Abhinav Guptacreate