docs: def memoizemethod(method):
      """
      Decorator to cause a method to cache it's results in self for each
      combination of inputs and return the cached result on subsequent calls.
      Does not support named arguments or arg values that are not hashable.
  
      >>> class Foo (object):
      ...   @memoizemethod
      ...   def foo(self, x, y=0):
      ...     print('running method with', x, y)
      ...     return x + y + 3
      ...
      >>> foo1 = Foo()
      >>> foo2 = Foo()
      >>> foo1.foo(10)
      running method with 10 0
      13
      >>> foo1.foo(10)
      13
      >>> foo2.foo(11, y=7)
      running method with 11 7
      21
      >>> foo2.foo(11)
      running method with 11 0
      14
      >>> foo2.foo(11, y=7)
      21
      >>> class Foo (object):
      ...   def __init__(self, lower):
      ...     self.lower = lower
      ...   @memoizemethod
      ...   def range_tuple(self, upper):
      ...     print('running function')
      ...     return tuple(i for i in range(self.lower, upper))
      ...   @memoizemethod
      ...   def range_iter(self, upper):
      ...     print('running function')
      ...     return (i for i in range(self.lower, upper))
      ...
      >>> foo = Foo(3)
      >>> foo.range_tuple(6)
      running function
      (3, 4, 5)
      >>> foo.range_tuple(7)
      running function
      (3, 4, 5, 6)
      >>> foo.range_tuple(6)
      (3, 4, 5)
      >>> foo.range_iter(6)
      Traceback (most recent call last):
      TypeError: Can't memoize a generator or non-hashable object!
      """
  
      @wraps(method)
      def _wrapper(self, *args, **kwargs):
          # NOTE:  a __dict__ check is performed here rather than using the
          # built-in hasattr function because hasattr will look up to an object's
          # class if the attr is not directly found in the object's dict.  That's
          # bad for this if the class itself has a memoized classmethod for
          # example that has been called before the memoized instance method,
          # then the instance method will use the class's result cache, causing
          # its results to be globally stored rather than on a per instance
          # basis.
          if '_memoized_results' not in self.__dict__:
              self._memoized_results = {}
          memoized_results = self._memoized_results
  
          key = (method.__name__, args, tuple(sorted(kwargs.items())))
          if key in memoized_results:
              return memoized_results[key]
          else:
              try:
                  result = method(self, *args, **kwargs)
              except KeyError as e:
                  if '__wrapped__' in str(e):
                      result = None  # is this the right thing to do?  happened during py3 conversion
                  else:
                      raise
              if isinstance(result, GeneratorType) or not isinstance(result, Hashable):
                  raise TypeError("Can't memoize a generator or non-hashable object!")
              return memoized_results.setdefault(key, result)
  
      return _wrapper