]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-104273: Remove redundant len() calls in argparse function (#104274)
authorBurak Saler <59198732+buraksaler@users.noreply.github.com>
Sun, 7 May 2023 23:43:50 +0000 (02:43 +0300)
committerGitHub <noreply@github.com>
Sun, 7 May 2023 23:43:50 +0000 (19:43 -0400)
Lib/argparse.py

index 68089a5c1e80b04fad7c88418b691a45a4c34aa5..f5f44ff02c0d38e1482504190372be355a641fbe 100644 (file)
@@ -345,21 +345,22 @@ class HelpFormatter(object):
                 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