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

Nikita Sobolev report at bugs.python.org
Thu Jan 27 05:25:13 EST 2022

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

Right now this works:

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

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: 411849
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>

More information about the New-bugs-announce mailing list