Proxy decorator_target.__get__ in TFDecorator
Prior to this change TFDecorator.__get__ mimicked the behaviour of functions via partial(self.__call__, instance). This is no needed as calling __get__ on a function would have a ~similar effect; and in fact incorrect if target implements a custom __get__ method. PiperOrigin-RevId: 234957239
This commit is contained in:
parent
775871944a
commit
86c8647f11
@ -59,7 +59,6 @@ from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import functools as _functools
|
||||
import traceback as _traceback
|
||||
|
||||
|
||||
@ -212,8 +211,8 @@ class TFDecorator(object):
|
||||
else:
|
||||
self.__doc__ = ''
|
||||
|
||||
def __get__(self, obj, objtype):
|
||||
return _functools.partial(self.__call__, obj)
|
||||
def __get__(self, instance, owner):
|
||||
return self._decorated_target.__get__(instance, owner)
|
||||
|
||||
def __call__(self, *args, **kwargs):
|
||||
return self._decorated_target(*args, **kwargs)
|
||||
|
@ -170,6 +170,17 @@ class TfDecoratorTest(test.TestCase):
|
||||
self.assertEqual('Return parameters.',
|
||||
TestDecoratedClass().return_params.__doc__)
|
||||
|
||||
def testTarget__get__IsProxied(self):
|
||||
class Descr(object):
|
||||
|
||||
def __get__(self, instance, owner):
|
||||
return self
|
||||
|
||||
class Foo(object):
|
||||
foo = tf_decorator.TFDecorator('Descr', Descr())
|
||||
|
||||
self.assertIsInstance(Foo.foo, Descr)
|
||||
|
||||
|
||||
def test_wrapper(*args, **kwargs):
|
||||
return test_function(*args, **kwargs)
|
||||
|
Loading…
Reference in New Issue
Block a user