Skip to content

bpo-43874: fix argparse sub parser error when sub parser has no "name" #25446

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

terencehonles
Copy link

@terencehonles terencehonles commented Apr 16, 2021

This change updates the following crash to instead produce the error message "%(prog)s: error: the following arguments are required: command".

Previously, when creating a simple required sub parser 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

https://bugs.python.org/issue43874

This change updates the following crash to instead produce the error
message "%(prog)s: error: the following arguments are required: command".

Previously, when creating a simple required sub parser 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
@the-knights-who-say-ni
Copy link

Hello, and thanks for your contribution!

I'm a bot set up to make sure that the project can legally accept this contribution by verifying everyone involved has signed the PSF contributor agreement (CLA).

CLA Missing

Our records indicate the following people have not signed the CLA:

@terencehonles

For legal reasons we need all the people listed to sign the CLA before we can look at your contribution. Please follow the steps outlined in the CPython devguide to rectify this issue.

If you have recently signed the CLA, please wait at least one business day
before our records are updated.

You can check yourself to see if the CLA has been received.

Thanks again for the contribution, we look forward to reviewing it!

@terencehonles terencehonles changed the title fix argparse sub parser error when sub parser has no "name" bp-43874: fix argparse sub parser error when sub parser has no "name" Apr 16, 2021
@terencehonles terencehonles changed the title bp-43874: fix argparse sub parser error when sub parser has no "name" bpo-43874: fix argparse sub parser error when sub parser has no "name" Apr 16, 2021
@rhettinger rhettinger self-requested a review April 18, 2021 04:15
@terencehonles
Copy link
Author

Looks like I had(?) to check if the CLA had been processed in order to have the bot update the labels.

@github-actions
Copy link

github-actions bot commented Jun 3, 2021

This PR is stale because it has been open for 30 days with no activity.

@github-actions github-actions bot added the stale Stale PR or inactive for long period of time. label Jun 3, 2021
@terencehonles
Copy link
Author

bump

@github-actions github-actions bot removed the stale Stale PR or inactive for long period of time. label Jun 9, 2021
@terencehonles
Copy link
Author

I believe this is a duplicate of #3680, and it looks like that one took awhile to go through

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants