This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: `textwrap.TextWrapper` leaks two intermediate vars into class namespace
Type: behavior Stage: patch review
Components: Library (Lib) Versions: Python 3.11
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: serhiy.storchaka, sobolevn
Priority: normal Keywords: patch

Created on 2022-01-27 10:25 by sobolevn, last changed 2022-04-11 14:59 by admin.

Pull Requests
URL Status Linked Edit
PR 30955 merged sobolevn, 2022-01-27 10:37
Messages (2)
msg411849 - (view) Author: Nikita Sobolev (sobolevn) * (Python triager) Date: 2022-01-27 10:25
Right now this works:

```
>>> import textwrap
>>> textwrap.TextWrapper.x
' '
>>> textwrap.TextWrapper.uspace
32
```

This happens because of these lines: https://github.com/python/cpython/blame/606e496dd6e2ace298532da200169124c26ae0f2/Lib/textwrap.py#L66-L69

Notice that `uspace` and `x` are both undocumented, untested, and unused in our code.

Similar variables in the same class body are then deleted from the scope:

```
    wordsep_simple_re = re.compile(r'(%s+)' % whitespace)
    del whitespace
```

1. https://github.com/python/cpython/blame/606e496dd6e2ace298532da200169124c26ae0f2/Lib/textwrap.py#L99
2. https://github.com/python/cpython/blame/606e496dd6e2ace298532da200169124c26ae0f2/Lib/textwrap.py#L106

I propose to add `del x, uspace` as well. These two probably should not be leaking and should not be exposed.
msg411859 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2022-01-27 11:56
New changeset 82bce54614f8116a40454fbbbf96a3fd460ca7df by Nikita Sobolev in branch 'main':
bpo-46544: Do not leak `x` and `uspace` in textwrap.TextWrapper (GH-30955)
https://github.com/python/cpython/commit/82bce54614f8116a40454fbbbf96a3fd460ca7df
History
Date User Action Args
2022-04-11 14:59:55adminsetgithub: 90702
2022-01-27 11:56:07serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg411859
2022-01-27 10:37:09sobolevnsetkeywords: + patch
stage: patch review
pull_requests: + pull_request29134
2022-01-27 10:25:13sobolevncreate