New submission from Victor Porton <por...@narod.ru>:
argparse produces a long unreadable, non-understandable for non-programmers error message when a subparser is not specified in the command line. Note that the below message contains Ubuntu specifics, but it seems it would be nearly as unclear on other OSes too. The worst thing about this error message is that to produce something readable instead I need to somehow parse the command string (or at least to catch TypeError). $ python3.7 test.py Traceback (most recent call last): File "test.py", line 10, in <module> args = parser.parse_args() File "/usr/lib/python3.7/argparse.py", line 1754, in parse_args args, argv = self.parse_known_args(args, namespace) File "/usr/lib/python3.7/argparse.py", line 1786, in parse_known_args namespace, args = self._parse_known_args(args, namespace) File "/usr/lib/python3.7/argparse.py", line 2021, in _parse_known_args ', '.join(required_actions)) TypeError: sequence item 0: expected str instance, NoneType found Error in sys.excepthook: Traceback (most recent call last): File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 63, in apport_excepthook from apport.fileutils import likely_packaged, get_recent_crashes File "/usr/lib/python3/dist-packages/apport/__init__.py", line 5, in <module> from apport.report import Report File "/usr/lib/python3/dist-packages/apport/report.py", line 30, in <module> import apport.fileutils File "/usr/lib/python3/dist-packages/apport/fileutils.py", line 23, in <module> from apport.packaging_impl import impl as packaging File "/usr/lib/python3/dist-packages/apport/packaging_impl.py", line 24, in <module> import apt File "/usr/lib/python3/dist-packages/apt/__init__.py", line 23, in <module> import apt_pkg ModuleNotFoundError: No module named 'apt_pkg' Original exception was: Traceback (most recent call last): File "test.py", line 10, in <module> args = parser.parse_args() File "/usr/lib/python3.7/argparse.py", line 1754, in parse_args args, argv = self.parse_known_args(args, namespace) File "/usr/lib/python3.7/argparse.py", line 1786, in parse_known_args namespace, args = self._parse_known_args(args, namespace) File "/usr/lib/python3.7/argparse.py", line 2021, in _parse_known_args ', '.join(required_actions)) TypeError: sequence item 0: expected str instance, NoneType found The script follows. #!/usr/bin/env python import argparse parser = argparse.ArgumentParser(description="Automatically process XML") subparsers = parser.add_subparsers(title='subcommands') chain_parser = subparsers.add_parser('chain', aliases=['c'], help='Automatically run a chain of transformations') args = parser.parse_args() ---------- components: Library (Lib) messages: 322164 nosy: porton priority: normal severity: normal status: open title: argparse: Missing subparser error message should be more clear type: behavior versions: Python 3.7 _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue34191> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com