Skip to content
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

argparse: usage text of arguments in mutually exclusive groups no longer wraps in Python 3.13 #121151

Closed
hamdanal opened this issue Jun 29, 2024 · 1 comment
Labels
3.13 bugs and security fixes 3.14 new features, bugs and security fixes type-bug An unexpected behavior, bug, or error

Comments

@hamdanal
Copy link
Contributor

hamdanal commented Jun 29, 2024

Bug report

Bug description:

Prior to Python 3.13, long usage text of arguments in mutually exclusive groups would wrap to multiple lines. This is no longer the case in Python 3.13:

import argparse

parser = argparse.ArgumentParser(
    prog="PROG", formatter_class=lambda prog: argparse.HelpFormatter(prog, width=80)
)
meg = parser.add_mutually_exclusive_group()
meg.add_argument("--op1", metavar="MET", nargs="?")
meg.add_argument("--op2", metavar=("MET1", "MET2"), nargs="*")
meg.add_argument("--op3", nargs="*")
meg.add_argument("--op4", metavar=("MET1", "MET2"), nargs="+")
meg.add_argument("--op5", nargs="+")
meg.add_argument("--op6", nargs=3)
meg.add_argument("--op7", metavar=("MET1", "MET2", "MET3"), nargs=3)
parser.print_help()

Python 3.12 output:

usage: PROG [-h] [--op1 [MET] | --op2 [MET1 [MET2 ...]] | --op3 [OP3 ...] |
            --op4 MET1 [MET2 ...] | --op5 OP5 [OP5 ...] | --op6 OP6 OP6 OP6 |
            --op7 MET1 MET2 MET3]

Python 3.13 output:

usage: PROG [-h]
            [--op1 [MET] | --op2 [MET1 [MET2 ...]] | --op3 [OP3 ...] | --op4 MET1 [MET2 ...] | --op5 OP5 [OP5 ...] | --op6 OP6 OP6 OP6 | --op7 MET1 MET2 MET3]

This is a regression I introduced in #105039. I am working on a fix for this.

/cc @encukou (sorry for the regression!)

CPython versions tested on:

3.12, 3.13

Operating systems tested on:

Linux

Linked PRs

@hamdanal hamdanal added the type-bug An unexpected behavior, bug, or error label Jun 29, 2024
@serhiy-storchaka serhiy-storchaka added 3.13 bugs and security fixes 3.14 new features, bugs and security fixes labels Jun 29, 2024
encukou pushed a commit that referenced this issue Aug 7, 2024
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Aug 7, 2024
…ts inside a mutually exclusive groups (pythonGH-121159)

(cherry picked from commit 013a092)

Co-authored-by: Ali Hamdan <ali.hamdan.dev@gmail.com>
blhsing pushed a commit to blhsing/cpython that referenced this issue Aug 22, 2024
Yhg1s pushed a commit that referenced this issue Sep 2, 2024
…nts inside a mutually exclusive groups (GH-121159) (#122777)

gh-121151: argparse: Fix wrapping of long usage text of arguments inside a mutually exclusive groups (GH-121159)
(cherry picked from commit 013a092)

Co-authored-by: Ali Hamdan <ali.hamdan.dev@gmail.com>
@savannahostrowski
Copy link
Member

Looks like this issue should have been closed with the merging of the above PRs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.13 bugs and security fixes 3.14 new features, bugs and security fixes type-bug An unexpected behavior, bug, or error
Projects
Status: Doc issues
Development

No branches or pull requests

3 participants