[New-bugs-announce] [issue46546] `importlib.metadata.DeprecatedList` leaks `method_name` variable

Nikita Sobolev report at bugs.python.org
Thu Jan 27 06:24:52 EST 2022


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

Right now in `DeprecatedList` there's a possibly unwated name leak of `method_name` here: https://github.com/python/cpython/blob/08c0ed2d9c0d01ad1a5adc0787bc75e4e90cbb85/Lib/importlib/metadata/__init__.py#L295-L308

```
for method_name in [
        '__setitem__',
        '__delitem__',
        'append',
        'reverse',
        'extend',
        'pop',
        'remove',
        '__iadd__',
        'insert',
        'sort',
    ]:
        locals()[method_name] = _wrap_deprecated_method(method_name)
```

Example:

```
>>> import importlib
>>> import importlib.metadata
>>> importlib.metadata.DeprecatedList.method_name
'sort'
```

Right now `method_name` is unused, undocumented, and untested.

My proposal is to add `del method_name` after the `for` loop, so it won't leak.

----------
components: Library (Lib)
messages: 411855
nosy: brett.cannon, jaraco, sobolevn
priority: normal
severity: normal
status: open
title: `importlib.metadata.DeprecatedList` leaks `method_name` variable
type: behavior
versions: Python 3.11

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


More information about the New-bugs-announce mailing list