Skip to content

Commit

Permalink
keep track of instance methods otherwise the cached _wrapper function…
Browse files Browse the repository at this point in the history
… will reference the first object to call __get__()
  • Loading branch information
lobocv committed Jan 9, 2017
1 parent db0cdea commit 97d87e8
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions pyperform/encapsulate.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def __init__(self, func):
self._wrapper = None
self.overridden = False
self.objclass = None
self.instancemethods = {}

@property
def func_name(self):
Expand Down Expand Up @@ -73,7 +74,8 @@ def __call__(self, instance, *args, **kwargs):

def __get__(self, obj, objtype):
"""Support instance methods."""
if self._wrapper is None:
if obj not in self.instancemethods:

self.objclass = obj.__class__
if obj not in Encapsulate.encapsulations:
Encapsulate.encapsulations[obj] = {self.func_name: []}
Expand Down Expand Up @@ -101,9 +103,9 @@ def __get__(self, obj, objtype):
if idx > 0 and any(call_order[:idx]):
enc.overridden = True

self._wrapper = partial(self.__call__, obj)
self.instancemethods[obj] = partial(self.__call__, obj)

return self._wrapper
return self.instancemethods[obj]

def __repr__(self):
return 'Encapsulation for %s' % self._func.func_name

0 comments on commit 97d87e8

Please sign in to comment.