diff --git a/newsfragments/4280.misc.rst b/newsfragments/4280.misc.rst new file mode 100644 index 0000000000..aff6a7ca1c --- /dev/null +++ b/newsfragments/4280.misc.rst @@ -0,0 +1 @@ +Avoid leaking loop variable ``name`` in ``AbstractSandbox`` -- by :user:`Avasam` diff --git a/setuptools/sandbox.py b/setuptools/sandbox.py index 6c095e029e..e5da9d86f0 100644 --- a/setuptools/sandbox.py +++ b/setuptools/sandbox.py @@ -309,9 +309,9 @@ def wrap(self, src, dst, *args, **kw): return wrap - for name in ["rename", "link", "symlink"]: - if hasattr(_os, name): - locals()[name] = _mk_dual_path_wrapper(name) + for __name in ["rename", "link", "symlink"]: + if hasattr(_os, __name): + locals()[__name] = _mk_dual_path_wrapper(__name) def _mk_single_path_wrapper(name: str, original=None): # type: ignore[misc] # https://github.com/pypa/setuptools/pull/4099 original = original or getattr(_os, name) @@ -326,7 +326,7 @@ def wrap(self, path, *args, **kw): if _file: _file = _mk_single_path_wrapper('file', _file) _open = _mk_single_path_wrapper('open', _open) - for name in [ + for __name in [ "stat", "listdir", "chdir", @@ -347,8 +347,8 @@ def wrap(self, path, *args, **kw): "pathconf", "access", ]: - if hasattr(_os, name): - locals()[name] = _mk_single_path_wrapper(name) + if hasattr(_os, __name): + locals()[__name] = _mk_single_path_wrapper(__name) def _mk_single_with_return(name: str): # type: ignore[misc] # https://github.com/pypa/setuptools/pull/4099 original = getattr(_os, name) @@ -361,9 +361,9 @@ def wrap(self, path, *args, **kw): return wrap - for name in ['readlink', 'tempnam']: - if hasattr(_os, name): - locals()[name] = _mk_single_with_return(name) + for __name in ['readlink', 'tempnam']: + if hasattr(_os, __name): + locals()[__name] = _mk_single_with_return(__name) def _mk_query(name: str): # type: ignore[misc] # https://github.com/pypa/setuptools/pull/4099 original = getattr(_os, name) @@ -376,9 +376,9 @@ def wrap(self, *args, **kw): return wrap - for name in ['getcwd', 'tmpnam']: - if hasattr(_os, name): - locals()[name] = _mk_query(name) + for __name in ['getcwd', 'tmpnam']: + if hasattr(_os, __name): + locals()[__name] = _mk_query(__name) def _validate_path(self, path): """Called to remap or validate any path, whether input or output"""