diff --git a/CHANGELOG b/CHANGELOG index 602eec5..e1366d2 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,11 @@ Changelog --------- +0.5 +``` + +* Fix binding with self as a kwarg. (Robert Collins #14) + 0.4 (2013-12-20) ```````````````` * Fix unbound methods getting their first parameter curried diff --git a/funcsigs/__init__.py b/funcsigs/__init__.py index fd2f47b..62f32b7 100644 --- a/funcsigs/__init__.py +++ b/funcsigs/__init__.py @@ -769,16 +769,16 @@ class Signature(object): # Process our '**kwargs'-like parameter arguments[kwargs_param.name] = kwargs else: - raise TypeError('too many keyword arguments') + raise TypeError('too many keyword arguments %r' % kwargs) return self._bound_arguments_cls(self, arguments) - def bind(self, *args, **kwargs): + def bind(*args, **kwargs): '''Get a BoundArguments object, that maps the passed `args` and `kwargs` to the function's signature. Raises `TypeError` if the passed arguments can not be bound. ''' - return self._bind(args, kwargs) + return args[0]._bind(args[1:], kwargs) def bind_partial(self, *args, **kwargs): '''Get a BoundArguments object, that partially maps the diff --git a/tests/test_inspect.py b/tests/test_inspect.py index 323c323..c6dc03d 100644 --- a/tests/test_inspect.py +++ b/tests/test_inspect.py @@ -1,6 +1,7 @@ # Copyright 2001-2013 Python Software Foundation; All Rights Reserved from __future__ import absolute_import, division, print_function import collections +import functools import sys try: @@ -982,6 +983,15 @@ def test_signature_bind_positional_only(self): self.call(test, a_po=1, b_po=2) """) + def test_bind_self(self): + class F: + def f(a, self): + return a, self + an_f = F() + partial_f = functools.partial(F.f, an_f) + ba = inspect.signature(partial_f).bind(self=10) + self.assertEqual((an_f, 10), partial_f(*ba.args, **ba.kwargs)) + class TestBoundArguments(unittest.TestCase):