Skip to content

Commit b4506ff

Browse files
Merge pull request #60 from tgoodlet/comprehensible_hook_call_error
Raise explicit error when impl called with pos args
2 parents 6689c91 + 7748ba0 commit b4506ff

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)