bpo-26510: Allow argparse add_subparsers to take required kwarg. by asottile · Pull Request #3027 · python/cpython (original) (raw)

I fixed the only crash I could find related to this: 6e61d8a

It was already triggerable with the following:

import argparse

parser = argparse.ArgumentParser() parsers = parser.add_subparsers() parsers.required = True parsers.add_parser('foo') parsers.add_parser('bar')

parser.parse_args()

$ python3.6 test.py
Traceback (most recent call last):
  File "test.py", line 9, in <module>
    parser.parse_args()
  File "/usr/lib/python3.6/argparse.py", line 1739, in parse_args
    args, argv = self.parse_known_args(args, namespace)
  File "/usr/lib/python3.6/argparse.py", line 1771, in parse_known_args
    namespace, args = self._parse_known_args(args, namespace)
  File "/usr/lib/python3.6/argparse.py", line 2006, in _parse_known_args
    ', '.join(required_actions))
TypeError: sequence item 0: expected str instance, NoneType found

The regression test I added alongside failed in the same way before patching (yay TDD).

Should this get called out separately?