Content-Length: 316106 | pFad | http://github.com/RustPython/RustPython/commit/1303ace453192996a6cfe649ee34c63cd6129474

AB Update textwrap from 3.13.5 (#5952) · RustPython/RustPython@1303ace · GitHub
Skip to content

Commit 1303ace

Browse files
authored
Update textwrap from 3.13.5 (#5952)
1 parent 3f9a5fd commit 1303ace

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

Lib/textwrap.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,7 @@ class TextWrapper:
6363
Append to the last line of truncated text.
6464
"""
6565

66-
unicode_whitespace_trans = {}
67-
uspace = ord(' ')
68-
for x in _whitespace:
69-
unicode_whitespace_trans[ord(x)] = uspace
66+
unicode_whitespace_trans = dict.fromkeys(map(ord, _whitespace), ord(' '))
7067

7168
# This funky little regex is just the trick for splitting
7269
# text up into word-wrappable chunks. E.g.
@@ -479,13 +476,19 @@ def indent(text, prefix, predicate=None):
479476
consist solely of whitespace characters.
480477
"""
481478
if predicate is None:
482-
def predicate(line):
483-
return line.strip()
484-
485-
def prefixed_lines():
486-
for line in text.splitlines(True):
487-
yield (prefix + line if predicate(line) else line)
488-
return ''.join(prefixed_lines())
479+
# str.splitlines(True) doesn't produce empty string.
480+
# ''.splitlines(True) => []
481+
# 'foo\n'.splitlines(True) => ['foo\n']
482+
# So we can use just `not s.isspace()` here.
483+
predicate = lambda s: not s.isspace()
484+
485+
prefixed_lines = []
486+
for line in text.splitlines(True):
487+
if predicate(line):
488+
prefixed_lines.append(prefix)
489+
prefixed_lines.append(line)
490+
491+
return ''.join(prefixed_lines)
489492

490493

491494
if __name__ == "__main__":

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/RustPython/RustPython/commit/1303ace453192996a6cfe649ee34c63cd6129474

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy