Skip to content

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

Description

@hamdanal

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

Activity

  1. added a commit that references this issue on Aug 7, 2024
  2. added a commit that references this issue on Aug 7, 2024
  3. added a commit that references this issue on Aug 22, 2024
  4. added a commit that references this issue on Sep 2, 2024
  5. savannahostrowski commented on Sep 24, 2024

    @savannahostrowski
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.13only security fixes3.14bugs and security fixestype-bugAn unexpected behavior, bug, or error

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions