Skip to content

Commit 6b296c2

Browse files
author
Tyler Goodlet
committed
Deprecate proc kwarg to call_historic()
It's a bad name, use `result_callback` instead. Resolves #120
1 parent 119836b commit 6b296c2

File tree

2 files changed

+40
-11
lines changed

2 files changed

+40
-11
lines changed

pluggy/hooks.py

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -257,20 +257,32 @@ def __call__(self, *args, **kwargs):
257257
)
258258
return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
259259

260-
def call_historic(self, proc=None, kwargs=None):
261-
""" call the hook with given ``kwargs`` for all registered plugins and
260+
def call_historic(self, result_callback=None, kwargs=None, proc=None):
261+
"""Call the hook with given ``kwargs`` for all registered plugins and
262262
for all plugins which will be registered afterwards.
263263
264-
If ``proc`` is not None it will be called for for each non-None result
265-
obtained from a hook implementation.
264+
If ``result_callback`` is not ``None`` it will be called for for each
265+
non-None result obtained from a hook implementation.
266+
267+
.. note::
268+
The ``proc`` argument is now deprecated.
266269
"""
267-
self._call_history.append((kwargs or {}, proc))
270+
if proc is not None:
271+
warnings.warn(
272+
"Support for `proc` argument is now deprecated and will be"
273+
"removed in an upcoming release.",
274+
DeprecationWarning
275+
)
276+
result_callback = proc
277+
278+
self._call_history.append((kwargs or {}, result_callback))
268279
# historizing hooks don't return results
269280
res = self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
270-
if proc is None:
281+
if result_callback is None:
271282
return
283+
# XXX: remember firstresult isn't compat with historic
272284
for x in res or []:
273-
proc(x)
285+
result_callback(x)
274286

275287
def call_extra(self, methods, kwargs):
276288
""" Call the hook with some additional temporarily participating
@@ -289,10 +301,10 @@ def _maybe_apply_history(self, method):
289301
"""Apply call history to a new hookimpl if it is marked as historic.
290302
"""
291303
if self.is_historic():
292-
for kwargs, proc in self._call_history:
304+
for kwargs, result_callback in self._call_history:
293305
res = self._hookexec(self, [method], kwargs)
294-
if res and proc is not None:
295-
proc(res[0])
306+
if res and result_callback is not None:
307+
result_callback(res[0])
296308

297309

298310
class HookImpl(object):

testing/test_pluginmanager.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ def he_method1(self, arg):
217217
pm.register(Plugin1())
218218

219219
he_method1 = pm.hook.he_method1
220-
he_method1.call_historic(proc=callback, kwargs=dict(arg=1))
220+
he_method1.call_historic(result_callback=callback, kwargs=dict(arg=1))
221221

222222
class Plugin2(object):
223223
@hookimpl
@@ -399,3 +399,20 @@ def example_hook():
399399
assert getattr(pm.hook, 'example_hook', None) # conftest.example_hook should be collected
400400
assert pm.parse_hookimpl_opts(conftest, 'example_blah') is None
401401
assert pm.parse_hookimpl_opts(conftest, 'example_hook') == {}
402+
403+
404+
def test_callhistoric_proc_deprecated(pm):
405+
"""``proc`` kwarg to `PluginMananger.call_historic()` is now officially
406+
deprecated.
407+
"""
408+
class P1(object):
409+
@hookspec(historic=True)
410+
@hookimpl
411+
def m(self, x):
412+
pass
413+
414+
p1 = P1()
415+
pm.add_hookspecs(p1)
416+
pm.register(p1)
417+
with pytest.deprecated_call():
418+
pm.hook.m.call_historic(kwargs=dict(x=10), proc=lambda res: res)

0 commit comments

Comments
 (0)