[Python-checkins] gh-104273: Remove redundant len() calls in argparse function (#104274)
terryjreedy
webhook-mailer at python.org
Sun May 7 19:44:25 EDT 2023
https://github.com/python/cpython/commit/01cc9c1ff79bf18fe34c05c6cd573e79ff9487c3
commit: 01cc9c1ff79bf18fe34c05c6cd573e79ff9487c3
branch: main
author: Burak Saler <59198732+buraksaler at users.noreply.github.com>
committer: terryjreedy <tjreedy at udel.edu>
date: 2023-05-07T19:43:50-04:00
summary:
gh-104273: Remove redundant len() calls in argparse function (#104274)
files:
M Lib/argparse.py
diff --git a/Lib/argparse.py b/Lib/argparse.py
index 68089a5c1e80..f5f44ff02c0d 100644
--- a/Lib/argparse.py
+++ b/Lib/argparse.py
@@ -345,21 +345,22 @@ def _format_usage(self, usage, actions, groups, prefix):
def get_lines(parts, indent, prefix=None):
lines = []
line = []
+ indent_length = len(indent)
if prefix is not None:
line_len = len(prefix) - 1
else:
- line_len = len(indent) - 1
+ line_len = indent_length - 1
for part in parts:
if line_len + 1 + len(part) > text_width and line:
lines.append(indent + ' '.join(line))
line = []
- line_len = len(indent) - 1
+ line_len = indent_length - 1
line.append(part)
line_len += len(part) + 1
if line:
lines.append(indent + ' '.join(line))
if prefix is not None:
- lines[0] = lines[0][len(indent):]
+ lines[0] = lines[0][indent_length:]
return lines
# if prog is short, follow it with optionals or positionals
More information about the Python-checkins
mailing list