Drop the getcallargs extension as its logic had to be moved to a higher level into...
authorA. Unique TensorFlower <gardener@tensorflow.org>
Mon, 26 Feb 2018 16:04:09 +0000 (08:04 -0800)
committerTensorFlower Gardener <gardener@tensorflow.org>
Mon, 26 Feb 2018 16:08:04 +0000 (08:08 -0800)
PiperOrigin-RevId: 187022717

tensorflow/contrib/py2tf/pyct/inspect_utils.py
tensorflow/contrib/py2tf/pyct/inspect_utils_test.py

index c1af95e..d19c6ed 100644 (file)
@@ -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.
 
index d96c3df..5528ac8 100644 (file)
@@ -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(