[New-bugs-announce] [issue46545] `textwrap.TextWrapper` leaks two intermediate vars into class namespace

Nikita Sobolev report at bugs.python.org
Thu Jan 27 05:26:55 EST 2022


New submission from Nikita Sobolev <mail at sobolevn.me>:

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.

----------
components: Library (Lib)
messages: 411850
nosy: sobolevn
priority: normal
severity: normal
status: open
title: `textwrap.TextWrapper` leaks two intermediate vars into class namespace
type: behavior
versions: Python 3.11

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue46545>
_______________________________________


More information about the New-bugs-announce mailing list