Simplify the stack walking in deprecation.py. Remove dependency on tf_stack.
PiperOrigin-RevId: 342742350 Change-Id: Ie976e0e45062361d4349a2d72a7941c221fb98be
This commit is contained in:
parent
d259d86efc
commit
42aab9b1f0
@ -20,8 +20,8 @@ from __future__ import print_function
|
|||||||
|
|
||||||
import collections
|
import collections
|
||||||
import functools
|
import functools
|
||||||
|
import inspect
|
||||||
import re
|
import re
|
||||||
import traceback
|
|
||||||
|
|
||||||
from tensorflow.python.platform import tf_logging as logging
|
from tensorflow.python.platform import tf_logging as logging
|
||||||
from tensorflow.python.util import decorator_utils
|
from tensorflow.python.util import decorator_utils
|
||||||
@ -100,15 +100,12 @@ def _validate_deprecation_args(date, instructions):
|
|||||||
|
|
||||||
def _call_location(outer=False):
|
def _call_location(outer=False):
|
||||||
"""Returns call location given level up from current call."""
|
"""Returns call location given level up from current call."""
|
||||||
stack = traceback.extract_stack(limit=4)
|
# Two up: <_call_location>, <_call_location's caller>
|
||||||
length = len(stack)
|
f = inspect.currentframe().f_back.f_back
|
||||||
if length == 0: # should never happen as we're in a function
|
parent = f.f_back
|
||||||
return 'UNKNOWN'
|
if outer and parent is not None:
|
||||||
index = length-4 if outer else length-3
|
f = parent
|
||||||
if index < 0:
|
return '{}:{}'.format(f.f_code.co_filename, f.f_lineno)
|
||||||
index = 0
|
|
||||||
frame = stack[index]
|
|
||||||
return '{}:{}'.format(frame.filename, frame.lineno)
|
|
||||||
|
|
||||||
|
|
||||||
def _wrap_decorator(wrapped_function):
|
def _wrap_decorator(wrapped_function):
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user