From 1442bc21161265b49740a04cb218b8e90dc76d7b Mon Sep 17 00:00:00 2001 From: Anna R Date: Sun, 4 Aug 2019 15:42:44 -0700 Subject: [PATCH] Print the right location where deprecated symbol is used. PiperOrigin-RevId: 261592387 --- tensorflow/python/util/module_wrapper.py | 7 ++++--- tensorflow/tools/api/tests/deprecation_test.py | 10 +++++----- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/tensorflow/python/util/module_wrapper.py b/tensorflow/python/util/module_wrapper.py index 7ca1e17b630..4478fcb61c2 100644 --- a/tensorflow/python/util/module_wrapper.py +++ b/tensorflow/python/util/module_wrapper.py @@ -39,9 +39,10 @@ def get_rename_v2(name): def _call_location(): - # We want to get stack frame 2 frames up from current frame, - # i.e. above _getattr__ and _call_location calls. - stack = tf_stack.extract_stack_file_and_line(max_length=3) + # We want to get stack frame 3 frames up from current frame, + # i.e. above __getattr__, _tfmw_add_deprecation_warning, + # and _call_location calls. + stack = tf_stack.extract_stack_file_and_line(max_length=4) if not stack: # should never happen as we're in a function return 'UNKNOWN' frame = stack[0] diff --git a/tensorflow/tools/api/tests/deprecation_test.py b/tensorflow/tools/api/tests/deprecation_test.py index 3a5cf0d043e..962b557d7a9 100644 --- a/tensorflow/tools/api/tests/deprecation_test.py +++ b/tensorflow/tools/api/tests/deprecation_test.py @@ -39,7 +39,7 @@ class DeprecationTest(test.TestCase): tf.tables_initializer() self.assertEqual(1, mock_warning.call_count) self.assertRegexpMatches(mock_warning.call_args[0][1], - "module_wrapper.py:") + "deprecation_test.py:") self.assertRegexpMatches( mock_warning.call_args[0][2], r"tables_initializer") self.assertRegexpMatches( @@ -60,7 +60,7 @@ class DeprecationTest(test.TestCase): tf.ragged.RaggedTensorValue(value, row_splits) self.assertEqual(1, mock_warning.call_count) self.assertRegexpMatches(mock_warning.call_args[0][1], - "module_wrapper.py:") + "deprecation_test.py:") self.assertRegexpMatches( mock_warning.call_args[0][2], r"ragged.RaggedTensorValue") self.assertRegexpMatches( @@ -83,7 +83,7 @@ class DeprecationTest(test.TestCase): tf.sparse_mask(array, mask_indices) self.assertEqual(1, mock_warning.call_count) self.assertRegexpMatches(mock_warning.call_args[0][1], - "module_wrapper.py:") + "deprecation_test.py:") self.assertRegexpMatches( mock_warning.call_args[0][2], r"sparse_mask") self.assertRegexpMatches( @@ -101,7 +101,7 @@ class DeprecationTest(test.TestCase): tf.VarLenFeature(tf.dtypes.int32) self.assertEqual(1, mock_warning.call_count) self.assertRegexpMatches(mock_warning.call_args[0][1], - "module_wrapper.py:") + "deprecation_test.py:") self.assertRegexpMatches( mock_warning.call_args[0][2], r"VarLenFeature") self.assertRegexpMatches( @@ -119,7 +119,7 @@ class DeprecationTest(test.TestCase): tf.saved_model.signature_constants.DEFAULT_SERVING_SIGNATURE_DEF_KEY # pylint: disable=pointless-statement self.assertEqual(1, mock_warning.call_count) self.assertRegexpMatches(mock_warning.call_args[0][1], - "module_wrapper.py:") + "deprecation_test.py:") self.assertRegexpMatches( mock_warning.call_args[0][2], r"saved_model.signature_constants.DEFAULT_SERVING_SIGNATURE_DEF_KEY")