Skip to content

Commit

Permalink
Avoid leaking "name" variable in AbstractSandbox (#4280)
Browse files Browse the repository at this point in the history
  • Loading branch information
abravalheri authored Apr 16, 2024
2 parents e92ad19 + 2b339b9 commit 683ad33
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
1 change: 1 addition & 0 deletions newsfragments/4280.misc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Avoid leaking loop variable ``name`` in ``AbstractSandbox`` -- by :user:`Avasam`
24 changes: 12 additions & 12 deletions setuptools/sandbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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",
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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"""
Expand Down

0 comments on commit 683ad33

Please sign in to comment.