Skip to content

Commit 7748ba0

Browse files
author
Tyler Goodlet
committed
Raise explicit error when impl called with pos args
Raise an explicit TypeError to alert the user that they are calling a hookimpl incorrectly with positional args; keyword args are allowed only. Add a test too. Fixes #53
1 parent 6689c91 commit 7748ba0

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

pluggy/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,9 @@ def _add_hookimpl(self, hookimpl):
664664
def __repr__(self):
665665
return "<_HookCaller %r>" % (self.name,)
666666

667-
def __call__(self, **kwargs):
667+
def __call__(self, *args, **kwargs):
668+
if args:
669+
raise TypeError("hook calling supports only keyword arguments")
668670
assert not self.is_historic()
669671
if self.argnames:
670672
notincall = set(self.argnames) - set(['__multicall__']) - set(

testing/test_hookrelay.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,11 @@ def hello(self, arg):
5757
"api hook 1"
5858

5959
pm.add_hookspecs(Api)
60-
pytest.raises(TypeError, lambda: pm.hook.hello(3))
60+
with pytest.raises(TypeError) as exc:
61+
pm.hook.hello(3)
62+
63+
comprehensible = "hook calling supports only keyword arguments"
64+
assert comprehensible in str(exc.value)
6165

6266

6367
def test_firstresult_definition(pm):

0 commit comments

Comments
 (0)