Skip to content

Commit 04b0fda

Browse files
committed
fix historic hook calling some more, add docstring
1 parent 950eda5 commit 04b0fda

File tree

3 files changed

+33
-7
lines changed

3 files changed

+33
-7
lines changed

CHANGELOG

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
0.4.1
2+
-----
3+
4+
- fix bug where callbacks for historic hooks would not be called for
5+
already registered plugins. Thanks Simon Gmizelj for the PR
6+
and holger krekel for further fixes.
7+
18
0.4.0
29
-----
310

pluggy.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
import sys
6868
import inspect
6969

70-
__version__ = '0.4.0'
70+
__version__ = '0.4.1'
7171

7272
__all__ = ["PluginManager", "PluginValidationError", "HookCallError",
7373
"HookspecMarker", "HookimplMarker"]
@@ -745,11 +745,17 @@ def __call__(self, **kwargs):
745745
return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
746746

747747
def call_historic(self, proc=None, kwargs=None):
748+
""" call the hook with given ``kwargs`` for all registered plugins and
749+
for all plugins which will be registered afterwards.
750+
751+
If ``proc`` is not None it will be called for for each non-None result
752+
obtained from a hook implementation.
753+
"""
748754
self._call_history.append((kwargs or {}, proc))
749755
# historizing hooks don't return results
750756
res = self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
751-
if res and proc is not None:
752-
proc(res[0])
757+
for x in res or []:
758+
proc(x)
753759

754760
def call_extra(self, methods, kwargs):
755761
""" Call the hook with some additional temporarily participating

testing/test_pluggy.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,24 +212,37 @@ def he_method1(self, arg):
212212
pm.register(Plugin())
213213
assert l == [10]
214214

215-
def test_with_immediate_result_memorized(self, pm):
215+
def test_with_callbacks_immediately_executed(self, pm):
216216
class Hooks:
217217
@hookspec(historic=True)
218218
def he_method1(self, arg):
219219
pass
220220
pm.add_hookspecs(Hooks)
221221

222-
class Plugin:
222+
class Plugin1:
223223
@hookimpl
224224
def he_method1(self, arg):
225225
return arg * 10
226226

227+
class Plugin2:
228+
@hookimpl
229+
def he_method1(self, arg):
230+
return arg * 20
231+
232+
class Plugin3:
233+
@hookimpl
234+
def he_method1(self, arg):
235+
return arg * 30
236+
227237
l = []
228-
pm.register(Plugin())
238+
pm.register(Plugin1())
239+
pm.register(Plugin2())
229240

230241
he_method1 = pm.hook.he_method1
231242
he_method1.call_historic(lambda res: l.append(res), dict(arg=1))
232-
assert l == [10]
243+
assert l == [20, 10]
244+
pm.register(Plugin3())
245+
assert l == [20, 10, 30]
233246

234247
def test_register_historic_incompat_hookwrapper(self, pm):
235248
class Hooks:

0 commit comments

Comments
 (0)