Skip to content

Commit 387c742

Browse files
committed
callers: remove useless try
Replaces #277. The extra try has no effect.
1 parent b181414 commit 387c742

1 file changed

Lines changed: 29 additions & 30 deletions

File tree

src/pluggy/_callers.py

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -90,41 +90,40 @@ def _multicall(
9090
__tracebackhide__ = True
9191
results: list[object] = []
9292
exception = None
93+
teardowns: list[Teardown] = []
9394
try: # run impl and wrapper setup functions in a loop
94-
teardowns: list[Teardown] = []
95-
try:
96-
for hook_impl in reversed(hook_impls):
97-
try:
98-
args = [caller_kwargs[argname] for argname in hook_impl.argnames]
99-
except KeyError as e:
100-
raise HookCallError(
101-
f"hook call must provide argument {e.args[0]!r}"
102-
) from e
95+
for hook_impl in reversed(hook_impls):
96+
try:
97+
args = [caller_kwargs[argname] for argname in hook_impl.argnames]
98+
except KeyError as e:
99+
raise HookCallError(
100+
f"hook call must provide argument {e.args[0]!r}"
101+
) from e
103102

104-
if hook_impl.hookwrapper:
105-
function_gen = run_old_style_hookwrapper(hook_impl, hook_name, args)
103+
if hook_impl.hookwrapper:
104+
function_gen = run_old_style_hookwrapper(hook_impl, hook_name, args)
106105

107-
next(function_gen) # first yield
108-
teardowns.append(function_gen)
106+
next(function_gen) # first yield
107+
teardowns.append(function_gen)
109108

110-
elif hook_impl.wrapper:
111-
try:
112-
# If this cast is not valid, a type error is raised below,
113-
# which is the desired response.
114-
res = hook_impl.function(*args)
115-
function_gen = cast(Generator[None, object, object], res)
116-
next(function_gen) # first yield
117-
teardowns.append(function_gen)
118-
except StopIteration:
119-
_raise_wrapfail(function_gen, "did not yield")
120-
else:
109+
elif hook_impl.wrapper:
110+
try:
111+
# If this cast is not valid, a type error is raised below,
112+
# which is the desired response.
121113
res = hook_impl.function(*args)
122-
if res is not None:
123-
results.append(res)
124-
if firstresult: # halt further impl calls
125-
break
126-
except BaseException as exc:
127-
exception = exc
114+
function_gen = cast(Generator[None, object, object], res)
115+
next(function_gen) # first yield
116+
teardowns.append(function_gen)
117+
except StopIteration:
118+
_raise_wrapfail(function_gen, "did not yield")
119+
else:
120+
res = hook_impl.function(*args)
121+
if res is not None:
122+
results.append(res)
123+
if firstresult: # halt further impl calls
124+
break
125+
except BaseException as exc:
126+
exception = exc
128127
finally:
129128
if firstresult: # first result hooks return a single value
130129
result = results[0] if results else None

0 commit comments

Comments
 (0)