[issue43874] argparse crashes on subparsers with no dest/metava

2021-08-03 Thread Terence Honles


Terence Honles  added the comment:

Closing as a duplicate of https://bugs.python.org/issue29298 (which was 
recently merged and caused conflicts with my patch)

--
resolution:  -> duplicate
stage: patch review -> resolved
status: open -> closed

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



[issue43874] argparse crashes on subparsers with no dest/metava

2021-04-24 Thread Terence Honles


Terence Honles  added the comment:

Sorry I didn't know what to put, and now that you changed it I understand what 
behavior means. Thanks for changing it.

Should I do anything further? Not sure how to proceed.

--

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



[issue43874] argparse crashes on subparsers with no dest/metava

2021-04-18 Thread Terence Honles


Terence Honles  added the comment:

Thanks for the context Paul. I didn't think to look in the tracker for an 
existing issue, sorry!

I'm not sure if documenting the requirement is sufficient or something that a 
user would go towards with the error as it is.

I _might_ suggest throwing an error if dest/metavar isn't provided when 
required is true but that would probably only work on creating the sub parser 
and not if setting attributes as I saw some tests doing.

If an error is thrown I'd expect it to be where I placed the default name and 
it to basically say sub parser has no name (and possibly suggest setting dest 
or metavar).

I think both might be confusing to the end user and likely something that a 
user relying on argparse might not test but expect to work (I am in that camp 
except I tested it... I was only wondering what it said). That is why I went 
with filling out the default of "command" (I also checked only one sub parser 
was allowed so that wouldn't be too ambiguous). Initially I went with 
"subcommand" because "subparser" didn't seem to make sense for an end user, but 
I settled with command since that's what some tests were using for dest and I 
liked it. I had also thought of expanding to all the options as one of the 
comments had in the other issue, but required argument: {command1,command2,...} 
looked a little funny and was less obvious what it meant since it could also 
looked like N arguments were missing and being represented in a collapsed 
representation.

--

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



[issue43874] argparse crashes on subparsers with no dest/metava

2021-04-16 Thread Terence Honles


New submission from Terence Honles :

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 "", line 1, in 
  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 
<https://bugs.python.org/issue43874>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com