from __future__ import absolute_import, print_function, unicode_literals

import functools
import collections

def save_method_args(method):
    """
    Wrap a method such that when it is called, we save the args and
    kwargs with which it was called.

    >>> class MyClass(object):
    ...     @save_method_args
    ...     def method(self, a, b):
    ...         print(a, b)
    >>> my_ob = MyClass()
    >>> my_ob.method(1, 2)
    1 2
    >>> my_ob._saved_method.args
    (1, 2)
    >>> my_ob._saved_method.kwargs
    {}
    >>> my_ob.method(a=3, b='foo')
    3 foo
    >>> my_ob._saved_method.args
    ()
    >>> my_ob._saved_method.kwargs == dict(a=3, b='foo')
    True
    """
    args_and_kwargs = collections.namedtuple('args_and_kwargs', 'args kwargs')
    @functools.wraps(method)
    def wrapper(self, *args, **kwargs):
        attr_name = '_saved_' + method.__name__
        attr = args_and_kwargs(args, kwargs)
        setattr(self, attr_name, attr)
        return method(self, *args, **kwargs)
    return wrapper

@@ -192,16 +192,8 @@
 led,
- we save
  the
@@ -205,20 +205,16 @@
  and
-%0A   
  kwargs 
 with
@@ -213,31 +213,34 @@
 rgs 
-with which it was calle
+are%0A    saved on the metho
 d.%0A%0A
@@ -661,16 +661,285 @@
     True
+%0A%0A    The arguments are stored on the instance, allowing for%0A    different instance to save different args.%0A%0A    %3E%3E%3E your_ob = MyClass()%0A    %3E%3E%3E your_ob.method(%7B3%7D, b=%5B4%5D)%0A    %7B3%7D %5B4%5D%0A    %3E%3E%3E your_ob._saved_method.args%0A    (%7B3%7D,)%0A    %3E%3E%3E my_ob._saved_method.args%0A    ()
 %0A    %22%22%22

Update docstring and expand doctests.