This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author remi.lapeyre
Recipients Gharg, paul.j3, remi.lapeyre, rhettinger
Date 2020-04-16.19:39:54
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1587065994.78.0.448752407942.issue40303@roundup.psfhosted.org>
In-reply-to
Content
Hi Gharg, this is expected, both because your program would not actually receive `--boolean=''` but `--boolean=`:

➜  ~ cat test.py
import sys

print(sys.argv)
➜  ~ python test.py --boolean=''
['test.py', '--boolean=']

and the way the type argument works. 

You can do what you are looking for by using:

➜  ~ cat test.py
import argparse

parser = argparse.ArgumentParser()
parser.add_argument('--boolean', action='store_const', const=True, default=False)

print(parser.parse_args())
➜  ~ python test.py --boolean
Namespace(boolean=True)
➜  ~ python test.py
Namespace(boolean=False)
History
Date User Action Args
2020-04-16 19:39:54remi.lapeyresetrecipients: + remi.lapeyre, rhettinger, paul.j3, Gharg
2020-04-16 19:39:54remi.lapeyresetmessageid: <1587065994.78.0.448752407942.issue40303@roundup.psfhosted.org>
2020-04-16 19:39:54remi.lapeyrelinkissue40303 messages
2020-04-16 19:39:54remi.lapeyrecreate