diff --git a/newsfragments/4593.feature.rst b/newsfragments/4593.feature.rst new file mode 100644 index 0000000000..4e3e4ed66b --- /dev/null +++ b/newsfragments/4593.feature.rst @@ -0,0 +1 @@ +Reraise error from ``setuptools.command.easy_install.auto_chmod`` instead of nonsensical ``TypeError: 'Exception' object is not subscriptable`` -- by :user:`Avasam` diff --git a/setuptools/command/easy_install.py b/setuptools/command/easy_install.py index 46c0a231eb..bdf9fa242b 100644 --- a/setuptools/command/easy_install.py +++ b/setuptools/command/easy_install.py @@ -34,7 +34,7 @@ from collections.abc import Iterable from glob import glob from sysconfig import get_path -from typing import TYPE_CHECKING +from typing import TYPE_CHECKING, Callable, TypeVar from jaraco.text import yield_lines @@ -89,6 +89,8 @@ 'get_exe_prefixes', ] +_T = TypeVar("_T") + def is_64bit(): return struct.calcsize("P") == 8 @@ -1786,13 +1788,14 @@ def _first_line_re(): return re.compile(first_line_re.pattern.decode()) -def auto_chmod(func, arg, exc): +# Must match shutil._OnExcCallback +def auto_chmod(func: Callable[..., _T], arg: str, exc: BaseException) -> _T: + """shutils onexc callback to automatically call chmod for certain functions.""" + # Only retry for scenarios known to have an issue if func in [os.unlink, os.remove] and os.name == 'nt': chmod(arg, stat.S_IWRITE) return func(arg) - et, ev, _ = sys.exc_info() - # TODO: This code doesn't make sense. What is it trying to do? - raise (ev[0], ev[1] + (" %s %s" % (func, arg))) # pyright: ignore[reportOptionalSubscript, reportIndexIssue] + raise exc def update_dist_caches(dist_path, fix_zipimporter_caches):