Skip to content

Commit ef2957a

Browse files
committed
Reraise sensible errors from auto_chmod
1 parent e55c19e commit ef2957a

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

Diff for: newsfragments/4593.feature.rst

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Reraise error from ``setuptools.command.easy_install.auto_chmod`` instead of nonsensical ``TypeError: 'Exception' object is not subscriptable`` -- by :user:`Avasam`

Diff for: setuptools/command/easy_install.py

+8-5
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
from collections.abc import Iterable
3535
from glob import glob
3636
from sysconfig import get_path
37-
from typing import TYPE_CHECKING
37+
from typing import TYPE_CHECKING, Callable, TypeVar
3838

3939
from jaraco.text import yield_lines
4040

@@ -89,6 +89,8 @@
8989
'get_exe_prefixes',
9090
]
9191

92+
_T = TypeVar("_T")
93+
9294

9395
def is_64bit():
9496
return struct.calcsize("P") == 8
@@ -1786,13 +1788,14 @@ def _first_line_re():
17861788
return re.compile(first_line_re.pattern.decode())
17871789

17881790

1789-
def auto_chmod(func, arg, exc):
1791+
# Must match shutil._OnExcCallback
1792+
def auto_chmod(func: Callable[..., _T], arg: str, exc: BaseException) -> _T:
1793+
"""shutils onexc callback to automatically call chmod for certain functions."""
1794+
# Only retry for scenarios known to have an issue
17901795
if func in [os.unlink, os.remove] and os.name == 'nt':
17911796
chmod(arg, stat.S_IWRITE)
17921797
return func(arg)
1793-
et, ev, _ = sys.exc_info()
1794-
# TODO: This code doesn't make sense. What is it trying to do?
1795-
raise (ev[0], ev[1] + (" %s %s" % (func, arg))) # pyright: ignore[reportOptionalSubscript, reportIndexIssue]
1798+
raise exc
17961799

17971800

17981801
def update_dist_caches(dist_path, fix_zipimporter_caches):

0 commit comments

Comments
 (0)