diff --git a/newsfragments/4554.misc.rst b/newsfragments/4554.misc.rst new file mode 100644 index 0000000000..9992f93441 --- /dev/null +++ b/newsfragments/4554.misc.rst @@ -0,0 +1 @@ +Removed ``setputools.sandbox``'s Python 2 ``builtins.file`` support -- by :user:`Avasam` diff --git a/setuptools/sandbox.py b/setuptools/sandbox.py index 5ba32a89b3..9a101b7137 100644 --- a/setuptools/sandbox.py +++ b/setuptools/sandbox.py @@ -22,10 +22,6 @@ import org.python.modules.posix.PosixModule as _os else: _os = sys.modules[os.name] -try: - _file = file # type: ignore[name-defined] # Check for global variable -except NameError: - _file = None _open = open @@ -285,15 +281,11 @@ def _copy(self, source): def __enter__(self): self._copy(self) - if _file: - builtins.file = self._file builtins.open = self._open self._active = True def __exit__(self, exc_type, exc_value, traceback): self._active = False - if _file: - builtins.file = _file builtins.open = _open self._copy(_os) @@ -326,8 +318,6 @@ def wrap(self, path, *args, **kw): return wrap - if _file: - _file = _mk_single_path_wrapper('file', _file) _open = _mk_single_path_wrapper('open', _open) for __name in [ "stat", @@ -444,13 +434,6 @@ def _violation(self, operation, *args, **kw): raise SandboxViolation(operation, args, kw) - if _file: - - def _file(self, path, mode='r', *args, **kw): - if mode not in ('r', 'rt', 'rb', 'rU', 'U') and not self._ok(path): - self._violation("file", path, mode, *args, **kw) - return _file(path, mode, *args, **kw) - def _open(self, path, mode='r', *args, **kw): if mode not in ('r', 'rt', 'rb', 'rU', 'U') and not self._ok(path): self._violation("open", path, mode, *args, **kw)