Skip to content

Commit ca39b4b

Browse files
authored
Merge pull request #30 from RonnyPfannschmidt/fix-17-detect-module
fix #17 by considering only routines
2 parents 71c1cb3 + df1f335 commit ca39b4b

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

CHANGELOG

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
- fix bug where callbacks for historic hooks would not be called for
55
already registered plugins. Thanks Simon Gmizelj for the PR
66
and holger krekel for further fixes.
7+
- fix #17 by considering only actual functions for hooks
8+
this removes the ability to register arbitrary callable objects
9+
which at first glance is a reasonable simplification,
10+
thanks RonnyPfannschmidt for report and pr.
711

812
0.4.0
913
-----

pluggy.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,8 @@ def register(self, plugin, name=None):
375375

376376
def parse_hookimpl_opts(self, plugin, name):
377377
method = getattr(plugin, name)
378+
if not inspect.isroutine(method):
379+
return
378380
try:
379381
res = getattr(method, self.project_name + "_impl", None)
380382
except Exception:

testing/test_pluggy.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -656,6 +656,15 @@ def hello_myhook(self, arg1):
656656
results = pm.hook.hello_myhook(arg1=17)
657657
assert results == [18, 18]
658658

659+
def test_prefix_hookimpl_dontmatch_module(self):
660+
pm = PluginManager(hookspec.project_name, "hello_")
661+
662+
class BadPlugin:
663+
hello_module = __import__('email')
664+
665+
pm.register(BadPlugin())
666+
pm.check_pending()
667+
659668

660669
def test_parse_hookimpl_override():
661670
class MyPluginManager(PluginManager):

0 commit comments

Comments
 (0)