Skip to content

Commit

Permalink
Merge pull request #60 from tgoodlet/comprehensible_hook_call_error
Browse files Browse the repository at this point in the history
Raise explicit error when impl called with pos args
  • Loading branch information
RonnyPfannschmidt authored Aug 24, 2017
2 parents 6689c91 + 7748ba0 commit b4506ff
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 3 additions & 1 deletion pluggy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,9 @@ def _add_hookimpl(self, hookimpl):
def __repr__(self):
return "<_HookCaller %r>" % (self.name,)

def __call__(self, **kwargs):
def __call__(self, *args, **kwargs):
if args:
raise TypeError("hook calling supports only keyword arguments")
assert not self.is_historic()
if self.argnames:
notincall = set(self.argnames) - set(['__multicall__']) - set(
Expand Down
6 changes: 5 additions & 1 deletion testing/test_hookrelay.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ def hello(self, arg):
"api hook 1"

pm.add_hookspecs(Api)
pytest.raises(TypeError, lambda: pm.hook.hello(3))
with pytest.raises(TypeError) as exc:
pm.hook.hello(3)

comprehensible = "hook calling supports only keyword arguments"
assert comprehensible in str(exc.value)


def test_firstresult_definition(pm):
Expand Down

0 comments on commit b4506ff

Please sign in to comment.