diff options
Diffstat (limited to 'tensorflow/tools/common/traverse.py')
-rw-r--r-- | tensorflow/tools/common/traverse.py | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/tensorflow/tools/common/traverse.py b/tensorflow/tools/common/traverse.py index 443838d968..9607f80686 100644 --- a/tensorflow/tools/common/traverse.py +++ b/tensorflow/tools/common/traverse.py @@ -18,9 +18,9 @@ from __future__ import absolute_import from __future__ import division from __future__ import print_function -import inspect import sys +from tensorflow.python.util import tf_inspect __all__ = ['traverse'] @@ -29,11 +29,11 @@ def _traverse_internal(root, visit, stack, path): """Internal helper for traverse.""" # Only traverse modules and classes - if not inspect.isclass(root) and not inspect.ismodule(root): + if not tf_inspect.isclass(root) and not tf_inspect.ismodule(root): return try: - children = inspect.getmembers(root) + children = tf_inspect.getmembers(root) except ImportError: # On some Python installations, some modules do not support enumerating # members (six in particular), leading to import errors. @@ -43,7 +43,8 @@ def _traverse_internal(root, visit, stack, path): visit(path, root, children) for name, child in children: # Do not descend into built-in modules - if inspect.ismodule(child) and child.__name__ in sys.builtin_module_names: + if tf_inspect.ismodule( + child) and child.__name__ in sys.builtin_module_names: continue # Break cycles @@ -72,8 +73,8 @@ def traverse(root, visit): never descends into built-in modules. `children`, a list of `(name, object)` pairs are determined by - `inspect.getmembers`. To avoid visiting parts of the tree, `children` can be - modified in place, using `del` or slice assignment. + `tf_inspect.getmembers`. To avoid visiting parts of the tree, `children` can + be modified in place, using `del` or slice assignment. Cycles (determined by reference equality, `is`) stop the traversal. A stack of objects is kept to find cycles. Objects forming cycles may appear in |