]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-46544: Do not leak `x` and `uspace` in textwrap.TextWrapper (GH-30955)
authorNikita Sobolev <mail@sobolevn.me>
Thu, 27 Jan 2022 11:55:58 +0000 (14:55 +0300)
committerGitHub <noreply@github.com>
Thu, 27 Jan 2022 11:55:58 +0000 (13:55 +0200)
Lib/textwrap.py
Misc/NEWS.d/next/Library/2022-01-27-13-30-02.bpo-46544.oFDVWj.rst [new file with mode: 0644]

index 841de9baecf5d8a497b26d1648081d69a4612e5e..98bedd27ea3a11995e2bf81a115df999767dc134 100644 (file)
@@ -63,10 +63,7 @@ class TextWrapper:
         Append to the last line of truncated text.
     """
 
-    unicode_whitespace_trans = {}
-    uspace = ord(' ')
-    for x in _whitespace:
-        unicode_whitespace_trans[ord(x)] = uspace
+    unicode_whitespace_trans = dict.fromkeys(map(ord, _whitespace), ord(' '))
 
     # This funky little regex is just the trick for splitting
     # text up into word-wrappable chunks.  E.g.
diff --git a/Misc/NEWS.d/next/Library/2022-01-27-13-30-02.bpo-46544.oFDVWj.rst b/Misc/NEWS.d/next/Library/2022-01-27-13-30-02.bpo-46544.oFDVWj.rst
new file mode 100644 (file)
index 0000000..63b47e5
--- /dev/null
@@ -0,0 +1,2 @@
+Don't leak ``x`` & ``uspace`` intermediate vars in
+:class:`textwrap.TextWrapper`.