New submission from Terence Honles <terence.hon...@gmail.com>:

When creating a simple required subparser the following will result in an error 
instead of an error message:

>>> from argparse import ArgumentParser
>>>
>>> parser = ArgumentParser()
>>> subparsers = parser.add_subparsers(required=True)
>>> subparsers.add_parser('one')
>>> subparsers.add_parser('two')
>>>
>>> parser.parse_args([])

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib64/python3.8/argparse.py", line 1768, in parse_args
    args, argv = self.parse_known_args(args, namespace)
  File "/usr/lib64/python3.8/argparse.py", line 1800, in parse_known_args
    namespace, args = self._parse_known_args(args, namespace)
  File "/usr/lib64/python3.8/argparse.py", line 2035, in _parse_known_args
    ', '.join(required_actions))
TypeError: sequence item 0: expected str instance, NoneType found

Looking at the code this is because the subparser is actually an action and 
when resolving the name it uses `None` as the subparser name which results in 
the error above.

----------
components: Library (Lib)
messages: 391250
nosy: terence.honles
priority: normal
pull_requests: 24176
severity: normal
status: open
title: argparse crashes on subparsers with no dest/metava
type: crash
versions: Python 3.10, Python 3.6, Python 3.7, Python 3.8, Python 3.9

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue43874>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to