diff options
author | A. Unique TensorFlower <gardener@tensorflow.org> | 2018-07-09 09:35:22 -0700 |
---|---|---|
committer | TensorFlower Gardener <gardener@tensorflow.org> | 2018-07-09 09:41:07 -0700 |
commit | db364b20b83cf97dcc4e5b0958cbfeb09f5a907f (patch) | |
tree | 73cf0b52ad783c937059394b0808993a419a62d4 /tensorflow/python/util | |
parent | 1d91f3532ee4df36749dda1a39b8a2a78232dd74 (diff) |
Adding getsourcefile and getsourcelines to tf_inspect.
PiperOrigin-RevId: 203779105
Diffstat (limited to 'tensorflow/python/util')
-rw-r--r-- | tensorflow/python/util/tf_inspect.py | 10 | ||||
-rw-r--r-- | tensorflow/python/util/tf_inspect_test.py | 12 |
2 files changed, 22 insertions, 0 deletions
diff --git a/tensorflow/python/util/tf_inspect.py b/tensorflow/python/util/tf_inspect.py index fbd6561767..ec20998bdd 100644 --- a/tensorflow/python/util/tf_inspect.py +++ b/tensorflow/python/util/tf_inspect.py @@ -300,6 +300,16 @@ def getsource(object): # pylint: disable=redefined-builtin return _inspect.getsource(tf_decorator.unwrap(object)[1]) +def getsourcefile(object): # pylint: disable=redefined-builtin + """TFDecorator-aware replacement for inspect.getsourcefile.""" + return _inspect.getsourcefile(tf_decorator.unwrap(object)[1]) + + +def getsourcelines(object): # pylint: disable=redefined-builtin + """TFDecorator-aware replacement for inspect.getsourcelines.""" + return _inspect.getsourcelines(tf_decorator.unwrap(object)[1]) + + def isbuiltin(object): # pylint: disable=redefined-builtin """TFDecorator-aware replacement for inspect.isbuiltin.""" return _inspect.isbuiltin(tf_decorator.unwrap(object)[1]) diff --git a/tensorflow/python/util/tf_inspect_test.py b/tensorflow/python/util/tf_inspect_test.py index beaf350de1..2f6021c7d8 100644 --- a/tensorflow/python/util/tf_inspect_test.py +++ b/tensorflow/python/util/tf_inspect_test.py @@ -326,6 +326,18 @@ def test_decorated_function_with_defaults(a, b=2, c='Hello'): self.assertEqual( expected, tf_inspect.getsource(test_decorated_function_with_defaults)) + def testGetSourceFile(self): + self.assertEqual( + __file__, + tf_inspect.getsourcefile(test_decorated_function_with_defaults)) + + def testGetSourceLines(self): + expected = inspect.getsourcelines( + test_decorated_function_with_defaults.decorated_target) + self.assertEqual( + expected, + tf_inspect.getsourcelines(test_decorated_function_with_defaults)) + def testIsBuiltin(self): self.assertEqual( tf_inspect.isbuiltin(TestDecoratedClass), |