[issue29298] argparse fails with required subparsers, un-named dest, and empty argv

2021-07-27 Thread Petr Viktorin


Change by Petr Viktorin :


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

___
Python tracker 

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



[issue29298] argparse fails with required subparsers, un-named dest, and empty argv

2021-07-23 Thread Petr Viktorin


Petr Viktorin  added the comment:


New changeset 097801844c99ea3916bebe1cc761257ea7083d34 by Miss Islington (bot) 
in branch '3.9':
bpo-29298: Fix crash with required subparsers without dest (GH-3680) (GH-27304)
https://github.com/python/cpython/commit/097801844c99ea3916bebe1cc761257ea7083d34


--

___
Python tracker 

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



[issue29298] argparse fails with required subparsers, un-named dest, and empty argv

2021-07-23 Thread Petr Viktorin


Petr Viktorin  added the comment:


New changeset c589992e09d0db7cb47d21d5948929e599fdbb94 by Miss Islington (bot) 
in branch '3.10':
bpo-29298: Fix crash with required subparsers without dest (GH-3680) (GH-27303)
https://github.com/python/cpython/commit/c589992e09d0db7cb47d21d5948929e599fdbb94


--
nosy: +petr.viktorin

___
Python tracker 

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



[issue29298] argparse fails with required subparsers, un-named dest, and empty argv

2021-07-23 Thread miss-islington


Change by miss-islington :


--
pull_requests: +25848
pull_request: https://github.com/python/cpython/pull/27304

___
Python tracker 

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



[issue29298] argparse fails with required subparsers, un-named dest, and empty argv

2021-07-23 Thread miss-islington


Change by miss-islington :


--
nosy: +miss-islington
nosy_count: 9.0 -> 10.0
pull_requests: +25847
pull_request: https://github.com/python/cpython/pull/27303

___
Python tracker 

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



[issue29298] argparse fails with required subparsers, un-named dest, and empty argv

2021-07-23 Thread miss-islington


miss-islington  added the comment:


New changeset 17575f73ce2cb9f3a4eb4cc416c690f9a4e7205c by Anthony Sottile in 
branch 'main':
bpo-29298: Fix crash with required subparsers without dest (GH-3680)
https://github.com/python/cpython/commit/17575f73ce2cb9f3a4eb4cc416c690f9a4e7205c


--

___
Python tracker 

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



[issue29298] argparse fails with required subparsers, un-named dest, and empty argv

2021-06-28 Thread Paulie Pena


Paulie Pena  added the comment:

I'd like to second this idea, since it's very confusing without it:
> while waiting for a fix, would it be possible to document in the argparse 
> documentation that the 'dest' parameter is required (at least temporarily) 
> for add_subparsers()?  (somewhere near 
> file:///usr/share/doc/python/html/library/argparse.html#sub-commands)

--
nosy: +paulie4

___
Python tracker 

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



[issue29298] argparse fails with required subparsers, un-named dest, and empty argv

2021-05-21 Thread Lucas Cimon


Change by Lucas Cimon :


--
nosy: +Lucas Cimon
nosy_count: 7.0 -> 8.0
pull_requests: +24884
pull_request: https://github.com/python/cpython/pull/26278

___
Python tracker 

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



[issue29298] argparse fails with required subparsers, un-named dest, and empty argv

2021-05-19 Thread Irit Katriel


Irit Katriel  added the comment:

crash means segfault, not unhandled exception.

--
nosy: +iritkatriel
type: crash -> behavior
versions: +Python 3.10, Python 3.11 -Python 2.7, Python 3.6, Python 3.7, Python 
3.8

___
Python tracker 

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



[issue29298] argparse fails with required subparsers, un-named dest, and empty argv

2020-02-19 Thread Ben Sokol


Change by Ben Sokol :


--
type: behavior -> crash
versions: +Python 3.8, Python 3.9

___
Python tracker 

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



[issue29298] argparse fails with required subparsers, un-named dest, and empty argv

2020-02-19 Thread Roundup Robot


Change by Roundup Robot :


--
pull_requests: +17945
pull_request: https://github.com/python/cpython/pull/18564

___
Python tracker 

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



[issue29298] argparse fails with required subparsers, un-named dest, and empty argv

2019-12-04 Thread Greg


Greg  added the comment:

while waiting for a fix, would it be possible to document in the argparse 
documentation that the 'dest' parameter is required (at least temporarily) for 
add_subparsers()?  (somewhere near 
file:///usr/share/doc/python/html/library/argparse.html#sub-commands)

gratuitous diff:  the pull request from 2017 would probably fix it.  my diffs 
are here (from: Python 3.8.0 (default, Oct 23 2019, 18:51:26).  (the pull 
request changes the utility '_get_action_name'; i wasn't sure of side-effects 
with other callers, so changed nearer the failure location.)

*** new/argparse.py 2019-12-05 11:16:37.618985247 +0530
--- old/argparse.py 2019-10-24 00:21:26.0 +0530
***
*** 2017,2030 
  for action in self._actions:
  if action not in seen_actions:
  if action.required:
! ra = _get_action_name(action)
! if ra is None:
! if not action.choices == {}:
! choice_strs = [str(choice) for choice in 
action.choices]
! ra = '{%s}' % ','.join(choice_strs)
! else:
! ra = ''
! required_actions.append(ra)
  else:
  # Convert action default now instead of doing it before
  # parsing arguments to avoid calling convert functions
--- 2017,2023 
  for action in self._actions:
  if action not in seen_actions:
  if action.required:
! required_actions.append(_get_action_name(action))
  else:
  # Convert action default now instead of doing it before
  # parsing arguments to avoid calling convert functions

--
nosy: +Minshall

___
Python tracker 

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



[issue29298] argparse fails with required subparsers, un-named dest, and empty argv

2018-11-20 Thread Mathias Ettinger


Mathias Ettinger  added the comment:

I was just hit by the very same issue and added the following test into 
`_get_action_name` to work around it:

elif isinstance(argument, _SubParsersAction):
return '{%s}' % ','.join(map(str, argument.choices))

I checked #9253 as referenced by paul j3 and like the `argument.name()` 
approach as well as it's less specific.

Any chance this can be addressed one way or another?

--
nosy: +Mathias Ettinger

___
Python tracker 

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



[issue29298] argparse fails with required subparsers, un-named dest, and empty argv

2018-06-05 Thread Miro Hrončok

Change by Miro Hrončok :


--
nosy: +hroncok

___
Python tracker 

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



[issue29298] argparse fails with required subparsers, un-named dest, and empty argv

2017-09-20 Thread Éric Araujo

Changes by Éric Araujo :


--
assignee:  -> merwok
nosy: +merwok
versions: +Python 2.7, Python 3.7

___
Python tracker 

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



[issue29298] argparse fails with required subparsers, un-named dest, and empty argv

2017-09-20 Thread Anthony Sottile

Changes by Anthony Sottile :


--
keywords: +patch
pull_requests: +3669
stage:  -> patch review

___
Python tracker 

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



[issue29298] argparse fails with required subparsers, un-named dest, and empty argv

2017-01-19 Thread paul j3

paul j3 added the comment:

http://bugs.python.org/issue9253  argparse: optional subparsers

Initially this bug/issue was a request to allow subparsers to be optional.  But 
with the change in how required actions are handled, subparsers are now 
optional by default.

As you learned from the SO question you now have to specify

subparsers.required = True

This is also discussed in my post (and following ones)

http://bugs.python.org/issue9253#msg186387

The default 'dest' is SUPPRESS.  The error you report occurs because the 
'required' error mechanism cannot handle that value. The suggest fix is to 
assign `dest`, even if it is not needed in the Namespace.  For now it is needed 
for error reporting.

Reviewing my suggested patches, it looks like I generate a 'dest' substitute 
from the subparser names.  So the 'required' error would look like

python: error: the following arguments are required: {cmd1, cmd2}

I think this issue can be closed with a reference to 9253. Or maybe that issue 
is too old, long and confusing, and we need a new bug/issue.

--
nosy: +paul.j3

___
Python tracker 

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



[issue29298] argparse fails with required subparsers, un-named dest, and empty argv

2017-01-17 Thread zachrahan

New submission from zachrahan:

In python 3.6 (and several versions back), using argparse with required 
subparsers will cause an unhelpful TypeError if the 'dest' parameter is not 
explicitly specified, and no arguments are provided.

Test case:
import argparse
parser = argparse.ArgumentParser()
subparsers = parser.add_subparsers()
subparsers.required = True
args = parser.parse_args([])

Observed result:
TypeError: sequence item 0: expected str instance, NoneType found

If the line above is changed to:
subparsers = parser.add_subparsers(dest='function')

Then the following is printed to stderr:
usage: python [-h] {} ...
python: error: the following arguments are required: function

This issue goes back at least several years:
http://stackoverflow.com/questions/23349349/argparse-with-required-subparser/23354355

Though it seems odd to not specify a dest in the add_subparsers line, the 
pattern is not completely useless. The below works fine without setting a 
'dest' in add_subparsers, except when argv is empty:
sub1 = subparsers.add_parser('print')
sub1.set_defaults(function=print)

However, an empty argv produces the unexpected TypeError above. I'm not sure if 
argparse should provide a more useful exception in this case, or if there is a 
clean way to do the right thing without a dest specified.

--
components: Library (Lib)
messages: 285646
nosy: zachrahan
priority: normal
severity: normal
status: open
title: argparse fails with required subparsers, un-named dest, and empty argv
type: behavior
versions: Python 3.6

___
Python tracker 

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