summaryrefslogtreecommitdiffstats
path: root/Lib/argparse.py
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2024-02-21 16:20:08 (GMT)
committerGitHub <noreply@github.com>2024-02-21 16:20:08 (GMT)
commita27c540d20b51d20c110fa8bc62ea040b185f958 (patch)
treef1717095f042871cb211b21903c82056a0447d42 /Lib/argparse.py
parent35e5bbc845d2f36059a5e8c48316849faa48b978 (diff)
downloadcpython-a27c540d20b51d20c110fa8bc62ea040b185f958.zip
cpython-a27c540d20b51d20c110fa8bc62ea040b185f958.tar.gz
cpython-a27c540d20b51d20c110fa8bc62ea040b185f958.tar.bz2
[3.11] gh-96310: Fix a traceback in argparse when all options in a mutually exclusive group are suppressed (GH-96311) (GH-115768)
Reproducer depends on terminal size - the traceback occurs when there's an option long enough so the usage line doesn't fit the terminal width. Option order is also important for reproducibility. Excluding empty groups (with all options suppressed) from inserts fixes the problem. (cherry picked from commit 5f7df88821347c5f44fc4e2c691e83a60a6c6cd5) Co-authored-by: Daniel Mach <daniel.mach@suse.com>
Diffstat (limited to 'Lib/argparse.py')
-rw-r--r--Lib/argparse.py2
1 files changed, 2 insertions, 0 deletions
diff --git a/Lib/argparse.py b/Lib/argparse.py
index ffbdbc2..57e6619 100644
--- a/Lib/argparse.py
+++ b/Lib/argparse.py
@@ -414,6 +414,8 @@ class HelpFormatter(object):
suppressed_actions_count += 1
exposed_actions_count = group_action_count - suppressed_actions_count
+ if not exposed_actions_count:
+ continue
if not group.required:
if start in inserts: