Skip to content

Commit eabefd4

Browse files
revert the traceback wrapping
1 parent 4f036be commit eabefd4

File tree

1 file changed

+9
-25
lines changed

1 file changed

+9
-25
lines changed

src/pip/_internal/utils/misc.py

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import contextlib
22
import errno
3-
import functools
43
import getpass
54
import hashlib
65
import io
@@ -125,26 +124,6 @@ def get_prog() -> str:
125124
return "pip"
126125

127126

128-
def bare_exc_to_onexc(exc_val: BaseException) -> ExcInfo:
129-
exc_ty = type(exc_val)
130-
tb = exc_val.__traceback__
131-
if tb is None:
132-
import inspect
133-
134-
frame = inspect.currentframe()
135-
assert frame is not None
136-
tb = TracebackType(None, frame, frame.f_lasti, frame.f_lineno)
137-
return (exc_ty, exc_val, tb)
138-
139-
140-
def extract_exc_info_arg(f: OnErr) -> OnExc:
141-
def g(fn: FunctionType, p: Path, e: BaseException) -> Any:
142-
info = bare_exc_to_onexc(e)
143-
return f(fn, p, info)
144-
145-
return functools.update_wrapper(g, f)
146-
147-
148127
# Retry every half second for up to 3 seconds
149128
# Tenacity raises RetryError by default, explicitly raise the original exception
150129
@retry(reraise=True, stop=stop_after_delay(3), wait=wait_fixed(0.5))
@@ -157,10 +136,15 @@ def rmtree(
157136
onexc = _onerror_ignore
158137
if onexc is None:
159138
onexc = _onerror_reraise
160-
handler: OnErr = partial(rmtree_errorhandler, onexc=onexc)
139+
handler: OnErr = partial(
140+
# `[func, path, Union[ExcInfo, BaseException]] -> Any` is equivalent to
141+
# `Union[([func, path, ExcInfo] -> Any), ([func, path, BaseException] -> Any)]`.
142+
cast(Union[OnExc, OnErr], rmtree_errorhandler),
143+
onexc=onexc,
144+
)
161145
if sys.version_info >= (3, 12):
162-
exc_handler = extract_exc_info_arg(handler)
163-
shutil.rmtree(dir, onexc=exc_handler)
146+
# See https://docs.python.org/3.12/whatsnew/3.12.html#shutil.
147+
shutil.rmtree(dir, onexc=handler)
164148
else:
165149
shutil.rmtree(dir, onerror=handler)
166150

@@ -178,7 +162,7 @@ def rmtree_errorhandler(
178162
path: str,
179163
exc_info: Union[ExcInfo, BaseException],
180164
*,
181-
onexc: Callable[..., Any] = _onerror_reraise,
165+
onexc: OnExc = _onerror_reraise,
182166
) -> None:
183167
"""
184168
`rmtree` error handler to 'force' a file remove (i.e. like `rm -f`).

0 commit comments

Comments
 (0)