Message317331
| Author |
Anthony Sottile |
| Recipients |
Anthony Sottile, bethard, bskinn, eric.araujo, gregory.p.smith, memeplex, ned.deily, paul.j3, serhiy.storchaka, wolma |
| Date |
2018年05月22日.19:21:53 |
| SpamBayes Score |
-1.0 |
| Marked as misclassified |
Yes |
| Message-id |
<1527016913.83.0.682650639539.issue33109@psf.upfronthosting.co.za> |
| In-reply-to |
| Content |
The bug is orthogonal, you can trigger it without the `required=` keyword argument via the (currently suggested) monkeypatch workaround which restores the pre-3.3 behaviour:
import argparse
parser = argparse.ArgumentParser()
subp = parser.add_subparsers()
subp.add_parser('test')
subp.required = True
parser.parse_args()
$ python3 test.py
Traceback (most recent call last):
File "test.py", line 7, in <module>
parser.parse_args()
File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/argparse.py", line 1730, in parse_args
args, argv = self.parse_known_args(args, namespace)
File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/argparse.py", line 1762, in parse_known_args
namespace, args = self._parse_known_args(args, namespace)
File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/argparse.py", line 1997, in _parse_known_args
', '.join(required_actions))
TypeError: sequence item 0: expected str instance, NoneType found
Also note that when `dest` is specified it works fine:
import argparse
parser = argparse.ArgumentParser()
subp = parser.add_subparsers(dest='cmd')
subp.add_parser('test')
subp.required = True
parser.parse_args()
$ python3 test.py
usage: test.py [-h] {test} ...
test.py: error: the following arguments are required: cmd |
|