From 546d30232a07c790de55ea75795f24614312c12a Mon Sep 17 00:00:00 2001 From: "A. Unique TensorFlower" Date: Mon, 26 Feb 2018 08:04:09 -0800 Subject: [PATCH] Drop the getcallargs extension as its logic had to be moved to a higher level into api.py. PiperOrigin-RevId: 187022717 --- tensorflow/contrib/py2tf/pyct/inspect_utils.py | 27 ---------------- .../contrib/py2tf/pyct/inspect_utils_test.py | 36 ---------------------- 2 files changed, 63 deletions(-) diff --git a/tensorflow/contrib/py2tf/pyct/inspect_utils.py b/tensorflow/contrib/py2tf/pyct/inspect_utils.py index c1af95e..d19c6ed 100644 --- a/tensorflow/contrib/py2tf/pyct/inspect_utils.py +++ b/tensorflow/contrib/py2tf/pyct/inspect_utils.py @@ -50,33 +50,6 @@ def getnamespace(f): return namespace -def getcallargs(c, *args, **kwargs): - """Extension of getcallargs to non-function callables.""" - if tf_inspect.isfunction(c) or tf_inspect.ismethod(c): - # The traditional getcallargs - return tf_inspect.getcallargs(c, *args, **kwargs) - - if tf_inspect.isclass(c): - # Constructors: use a sentinel to remove the self argument. - self_sentinel = object() - arg_map = tf_inspect.getcallargs( - c.__init__, self_sentinel, *args, **kwargs) - # Find and remove the self arg. We cannot assume it's called 'self'. - self_arg_name = None - for name, value in arg_map.items(): - if value is self_sentinel: - self_arg_name = name - break - del arg_map[self_arg_name] - return arg_map - - if hasattr(c, '__call__'): - # Callable objects: map self to the object itself - return tf_inspect.getcallargs(c.__call__, *args, **kwargs) - - raise NotImplementedError('unknown callable "%s"' % type(c)) - - def getmethodclass(m): """Resolves a function's owner, e.g. a method's class. diff --git a/tensorflow/contrib/py2tf/pyct/inspect_utils_test.py b/tensorflow/contrib/py2tf/pyct/inspect_utils_test.py index d96c3df..5528ac8 100644 --- a/tensorflow/contrib/py2tf/pyct/inspect_utils_test.py +++ b/tensorflow/contrib/py2tf/pyct/inspect_utils_test.py @@ -127,42 +127,6 @@ class InspectUtilsTest(test.TestCase): self.assertEqual(ns['closed_over_primitive'], closed_over_primitive) self.assertTrue('local_var' not in ns) - def test_getcallargs_constructor(self): - - class TestSuperclass(object): - - def __init__(self, x): - pass - - class TestCallable(TestSuperclass): - pass - - self.assertDictEqual({ - 'x': 1 - }, inspect_utils.getcallargs(TestCallable, 1)) - - def test_getcallargs_object(self): - - class TestCallable(object): - - def __call__(self, x): - pass - - obj = TestCallable() - self.assertDictEqual({ - 'self': obj, - 'x': 1 - }, inspect_utils.getcallargs(obj, 1)) - - def test_getcallargs_function(self): - - def test_fn(x): - return x + 1 - - self.assertDictEqual({ - 'x': 1 - }, inspect_utils.getcallargs(test_fn, 1)) - def test_getmethodclass(self): self.assertEqual( -- 2.7.4