Skip to content

Commit 5ea8116

Browse files
author
Tyler Goodlet
committed
Drop __multicall__!
Drop the `_LegacyMultiCall` type and it's recursion "fun". We've got a faster and simpler function-loop approach now with `pluggy.callers._multicall()` it's been doing great in production! Resolves pytest-dev#59
1 parent 119836b commit 5ea8116

File tree

2 files changed

+3
-83
lines changed

2 files changed

+3
-83
lines changed

pluggy/callers.py

Lines changed: 0 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -77,77 +77,6 @@ def get_result(self):
7777
_reraise(*ex) # noqa
7878

7979

80-
def _wrapped_call(wrap_controller, func):
81-
""" Wrap calling to a function with a generator which needs to yield
82-
exactly once. The yield point will trigger calling the wrapped function
83-
and return its ``_Result`` to the yield point. The generator then needs
84-
to finish (raise StopIteration) in order for the wrapped call to complete.
85-
"""
86-
try:
87-
next(wrap_controller) # first yield
88-
except StopIteration:
89-
_raise_wrapfail(wrap_controller, "did not yield")
90-
call_outcome = _Result.from_call(func)
91-
try:
92-
wrap_controller.send(call_outcome)
93-
_raise_wrapfail(wrap_controller, "has second yield")
94-
except StopIteration:
95-
pass
96-
return call_outcome.get_result()
97-
98-
99-
class _LegacyMultiCall(object):
100-
""" execute a call into multiple python functions/methods. """
101-
102-
# XXX note that the __multicall__ argument is supported only
103-
# for pytest compatibility reasons. It was never officially
104-
# supported there and is explicitely deprecated since 2.8
105-
# so we can remove it soon, allowing to avoid the below recursion
106-
# in execute() and simplify/speed up the execute loop.
107-
108-
def __init__(self, hook_impls, kwargs, firstresult=False):
109-
self.hook_impls = hook_impls
110-
self.caller_kwargs = kwargs # come from _HookCaller.__call__()
111-
self.caller_kwargs["__multicall__"] = self
112-
self.firstresult = firstresult
113-
114-
def execute(self):
115-
caller_kwargs = self.caller_kwargs
116-
self.results = results = []
117-
firstresult = self.firstresult
118-
119-
while self.hook_impls:
120-
hook_impl = self.hook_impls.pop()
121-
try:
122-
args = [caller_kwargs[argname] for argname in hook_impl.argnames]
123-
except KeyError:
124-
for argname in hook_impl.argnames:
125-
if argname not in caller_kwargs:
126-
raise HookCallError(
127-
"hook call must provide argument %r" % (argname,))
128-
if hook_impl.hookwrapper:
129-
return _wrapped_call(hook_impl.function(*args), self.execute)
130-
res = hook_impl.function(*args)
131-
if res is not None:
132-
if firstresult:
133-
return res
134-
results.append(res)
135-
136-
if not firstresult:
137-
return results
138-
139-
def __repr__(self):
140-
status = "%d meths" % (len(self.hook_impls),)
141-
if hasattr(self, "results"):
142-
status = ("%d results, " % len(self.results)) + status
143-
return "<_MultiCall %s, kwargs=%r>" % (status, self.caller_kwargs)
144-
145-
146-
def _legacymulticall(hook_impls, caller_kwargs, firstresult=False):
147-
return _LegacyMultiCall(
148-
hook_impls, caller_kwargs, firstresult=firstresult).execute()
149-
150-
15180
def _multicall(hook_impls, caller_kwargs, firstresult=False):
15281
"""Execute a call into multiple python functions/methods and return the
15382
result(s).

pluggy/hooks.py

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"""
44
import inspect
55
import warnings
6-
from .callers import _legacymulticall, _multicall
6+
from .callers import _multicall
77

88

99
class HookspecMarker(object):
@@ -192,7 +192,7 @@ def set_specification(self, specmodule_or_class, spec_opts):
192192
specfunc = getattr(specmodule_or_class, self.name)
193193
# get spec arg signature
194194
argnames, self.kwargnames = varnames(specfunc)
195-
self.argnames = ["__multicall__"] + list(argnames)
195+
self.argnames = list(argnames)
196196
self.spec_opts.update(spec_opts)
197197
if spec_opts.get("historic"):
198198
self._call_history = []
@@ -230,14 +230,6 @@ def _add_hookimpl(self, hookimpl):
230230
i -= 1
231231
methods.insert(i + 1, hookimpl)
232232

233-
if '__multicall__' in hookimpl.argnames:
234-
warnings.warn(
235-
"Support for __multicall__ is now deprecated and will be"
236-
"removed in an upcoming release.",
237-
DeprecationWarning
238-
)
239-
self.multicall = _legacymulticall
240-
241233
def __repr__(self):
242234
return "<_HookCaller %r>" % (self.name,)
243235

@@ -246,8 +238,7 @@ def __call__(self, *args, **kwargs):
246238
raise TypeError("hook calling supports only keyword arguments")
247239
assert not self.is_historic()
248240
if self.argnames:
249-
notincall = set(self.argnames) - set(['__multicall__']) - set(
250-
kwargs.keys())
241+
notincall = set(self.argnames) - set(kwargs.keys())
251242
if notincall:
252243
warnings.warn(
253244
"Argument(s) {} which are declared in the hookspec "

0 commit comments

Comments
 (0)