Q:

getattr on a decorated method generates a TypeError

I needed memoization to be applied at an instance level, so I used the following decorator:
from functools import partial, update_wrapper

class memoize(object):
    def __init__(self, func):
        self.func = func
        update_wrapper(self, func)

    def __get__(self, obj):
        if obj is None:
            return self.func
        return partial(self, obj)

    def __call__(self, *args, **kwargs):
        obj = args[0]
        try:
            cache = obj.__cache__
        except AttributeError:
            cache = obj.__cache__ = {}
        key = (self.func, args[1:], frozenset(kwargs.items()))
        try:
            res = cache[key]
        except KeyError:
            res = cache[key] = self.func(*args, **kwargs)
        return res

As applied:
class A(object):
    def __init__(self, parent):
        self.parent = parent

    def undecorated_method(self, pose, frame):
        pass

    @memoize
    def decorated_method(self, pose, frame):
        pass

The only way I found by which I can access it is by doing A.__dict__["decorated_method"]. Trying getattr(A, "decorated_method") or getattr(A(5), "decorated_method") or A.decorated_method etc all fail with a:
TypeError: __get__() takes exactly 2 arguments (3 given)

The actual traceback from the real code is:
Traceback (most recent call last):
  File "./regenerate_launch_files.py", line 145, in <module>
    main()
  File "./regenerate_launch_files.py", line 130, in main
    verify_coeffs(method, past_image_keys)
  File "./regenerate_launch_files.py", line 117, in verify_coeffs
    if not (inspect.ismethod(getattr(evaluator, component))
TypeError: __get__() takes exactly 2 arguments (3 given)

Calling the undecorated method has no problem.
>>> getattr(A, "undecorated_method")
<unbound method __main__.A.undecorated_method>

(In Python 3, "undecorated method" would give <function __main__.A.undecorated_method>, but getattr(A, "decorated_method") still fails with TypeError: __get__() takes 2 positional arguments but 3 were given.) 
What might be causing that? How can I find what the arguments given were? How can I debug and/or fix it?

A:

getattr was passing the following arguments to memoize's __get__:
* `self`
* `None`
* `<class '__main__.A'>`

That was what was causing the errors. To fix it:
def __get__(self, instance, owner):
    if instance is None:
        return self.func
    return partial(self, instance)

