Issue 14392: type=bool doesn't raise error in argparse.Action (original) (raw)

Created on 2012-03-23 07:03 by shima__shima, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
argparse.py.patch shima__shima,2012-03-23 07:03
Messages (6)
msg156636 - (view) Author: Toshihiro Kamishima (shima__shima) Date: 2012-03-23 07:03
According to the documentation of "argparse.Action", a keyword 'bool' is not allowed for type argument, but it doesn't raise no errors. One possible way to fix this issue is to check in the "argparse._ActionsContainer.add_argument" method.
msg156728 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2012-03-25 00:56
This change maked the error message wrong if bool is rejected.
msg156729 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2012-03-25 00:59
The corresponding current code in 3.2 and 3.3 is the same.
msg156745 - (view) Author: Toshihiro Kamishima (shima__shima) Date: 2012-03-25 09:05
Thank you for your response. My patch makes raise error by minimal change, but it may be better to raise NameError as in a case specifying "type=string" in 2.7.2. Similar to the case "type=bool", specifications, such as "type=unicode" or "type=long", don't raise errors. Because the set of problematic keywords are different between 2.7.x and 3.3.x, I have no idea to completely fix this problem.
msg166062 - (view) Author: Steven Bethard (bethard) * (Python committer) Date: 2012-07-21 20:19
I can't find anywhere in the documentation where type=bool, type=unicode or type=long are disallowed. They shouldn't be disallowed. If you want to pass type=bool, argparse should not stop you. And it currently doesn't: >>> parser = argparse.ArgumentParser() >>> parser.add_argument('foo', type=bool) >>> parser.parse_args(['']) Namespace(foo=False) >>> parser.parse_args(['x']) Namespace(foo=True)
msg166093 - (view) Author: Toshihiro Kamishima (shima__shima) Date: 2012-07-22 00:10
> - type -- The type which the command-line arguments should be converted > to, should be one of 'string', 'int', 'float', 'complex' or a > callable object that accepts a single string argument. If None, > 'string' is assumed. I misunderstood this sentence in the docstring of arcparse.Action because `bool` or `unicode` is not appeared in this list, which are callables. So, I close this issue.
History
Date User Action Args
2022-04-11 14:57:28 admin set github: 58600
2017-01-10 00:45:51 paul.j3 set nosy: + paul.j3
2012-07-22 00:10:21 shima__shima set status: open -> closedresolution: rejectedmessages: +
2012-07-21 20:19:39 bethard set messages: +
2012-03-25 09:05:40 shima__shima set messages: +
2012-03-25 00:59:03 terry.reedy set messages: + versions: + Python 3.2, Python 3.3
2012-03-25 00:56:05 terry.reedy set nosy: + terry.reedy, bethardmessages: + type: behaviorstage: test needed
2012-03-23 07:03:28 shima__shima create