[Python-checkins] bpo-46544: Do not leak `x` and `uspace` in textwrap.TextWrapper (GH-30955)
serhiy-storchaka
webhook-mailer at python.org
Thu Jan 27 06:56:08 EST 2022
https://github.com/python/cpython/commit/82bce54614f8116a40454fbbbf96a3fd460ca7df
commit: 82bce54614f8116a40454fbbbf96a3fd460ca7df
branch: main
author: Nikita Sobolev <mail at sobolevn.me>
committer: serhiy-storchaka <storchaka at gmail.com>
date: 2022-01-27T13:55:58+02:00
summary:
bpo-46544: Do not leak `x` and `uspace` in textwrap.TextWrapper (GH-30955)
files:
A Misc/NEWS.d/next/Library/2022-01-27-13-30-02.bpo-46544.oFDVWj.rst
M Lib/textwrap.py
diff --git a/Lib/textwrap.py b/Lib/textwrap.py
index 841de9baecf5d..98bedd27ea3a1 100644
--- a/Lib/textwrap.py
+++ b/Lib/textwrap.py
@@ -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
index 0000000000000..63b47e55f1b18
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2022-01-27-13-30-02.bpo-46544.oFDVWj.rst
@@ -0,0 +1,2 @@
+Don't leak ``x`` & ``uspace`` intermediate vars in
+:class:`textwrap.TextWrapper`.
More information about the Python-checkins
mailing list