Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2691c12

Browse files
martinwicketensorflower-gardener
authored andcommitted
Fix a bad comment.
Change: 143889993
1 parent 367078a commit 2691c12

9 files changed

Lines changed: 193 additions & 26 deletions

File tree

tensorflow/python/framework/python_op_gen.cc

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -482,8 +482,8 @@ static string GetPythonOp(const OpDef& op_def, bool is_hidden, string op_name) {
482482

483483
// Prepare a NamedTuple type to hold the outputs, if there are multiple
484484
if (num_outs > 1) {
485-
const string tuple_type_prefix =
486-
strings::StrCat("_", op_def.name(), "Output = collections.namedtuple(");
485+
const string tuple_type_prefix = strings::StrCat(
486+
"_", op_def.name(), "Output = _collections.namedtuple(");
487487
const string tuple_type_suffix = strings::StrCat(
488488
"\"", op_def.name(), "\", ", lower_op_name_outputs, ")");
489489
strings::Appendf(
@@ -656,18 +656,18 @@ string GetPythonOps(const OpList& ops, const std::vector<string>& hidden_ops,
656656
This file is MACHINE GENERATED! Do not edit.
657657
"""
658658
659-
import collections
659+
import collections as _collections
660660
661-
from google.protobuf import text_format
661+
from google.protobuf import text_format as _text_format
662662
663-
from tensorflow.core.framework import op_def_pb2
663+
from tensorflow.core.framework import op_def_pb2 as _op_def_pb2
664664
665665
# Needed to trigger the call to _set_call_cpp_shape_fn.
666-
from tensorflow.python.framework import common_shapes
666+
from tensorflow.python.framework import common_shapes as _common_shapes
667667
668-
from tensorflow.python.framework import op_def_registry
669-
from tensorflow.python.framework import ops
670-
from tensorflow.python.framework import op_def_library
668+
from tensorflow.python.framework import op_def_registry as _op_def_registry
669+
from tensorflow.python.framework import ops as _ops
670+
from tensorflow.python.framework import op_def_library as _op_def_library
671671
)");
672672

673673
// We'll make a copy of ops that filters out descriptions.
@@ -699,7 +699,7 @@ from tensorflow.python.framework import op_def_library
699699
GetPythonOp(op_def, is_hidden, lower_case_name));
700700

701701
if (!require_shapes) {
702-
strings::Appendf(&result, "ops.RegisterShape(\"%s\")(None)\n",
702+
strings::Appendf(&result, "_ops.RegisterShape(\"%s\")(None)\n",
703703
op_def.name().c_str());
704704
}
705705

@@ -709,10 +709,10 @@ from tensorflow.python.framework import op_def_library
709709
}
710710

711711
strings::Appendf(&result, R"(def _InitOpDefLibrary():
712-
op_list = op_def_pb2.OpList()
713-
text_format.Merge(_InitOpDefLibrary.op_list_ascii, op_list)
714-
op_def_registry.register_op_list(op_list)
715-
op_def_lib = op_def_library.OpDefLibrary()
712+
op_list = _op_def_pb2.OpList()
713+
_text_format.Merge(_InitOpDefLibrary.op_list_ascii, op_list)
714+
_op_def_registry.register_op_list(op_list)
715+
op_def_lib = _op_def_library.OpDefLibrary()
716716
op_def_lib.add_op_list(op_list)
717717
return op_def_lib
718718

tensorflow/python/ops/array_ops.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@
105105
import numpy as np
106106
import six
107107

108+
from tensorflow.python.framework import common_shapes
108109
from tensorflow.python.framework import constant_op
109110
from tensorflow.python.framework import dtypes
110111
from tensorflow.python.framework import ops

tensorflow/python/ops/sdca_ops.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,18 @@
2727
from __future__ import division
2828
from __future__ import print_function
2929

30-
import numpy as np
31-
32-
from tensorflow.python import pywrap_tensorflow
3330
from tensorflow.python.framework import ops
31+
3432
# go/tf-wildcard-import
3533
# pylint: disable=wildcard-import
3634
from tensorflow.python.ops.gen_sdca_ops import *
3735
# pylint: enable=wildcard-import
3836

39-
# pylint: disable=anomalous-backslash-in-string,protected-access
37+
from tensorflow.python.util.all_util import remove_undocumented
38+
4039
ops.NotDifferentiable("SdcaFprint")
4140
ops.NotDifferentiable("SdcaOptimizer")
4241
ops.NotDifferentiable("SdcaShrinkL1")
42+
43+
44+
remove_undocumented(__name__)

tensorflow/python/platform/test.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,18 +64,19 @@ def testSquare(self):
6464
from __future__ import division
6565
from __future__ import print_function
6666

67+
# pylint: disable=g-bad-import-order
6768
from tensorflow.python.client import device_lib as _device_lib
6869
from tensorflow.python.framework import test_util as _test_util
6970
from tensorflow.python.platform import googletest as _googletest
7071
from tensorflow.python.util.all_util import remove_undocumented
7172

7273
# pylint: disable=unused-import
73-
from tensorflow.python.framework.test_util import TensorFlowTestCase as TestCase
7474
from tensorflow.python.framework.test_util import assert_equal_graph_def
75+
from tensorflow.python.framework.test_util import TensorFlowTestCase as TestCase
7576

7677
from tensorflow.python.ops.gradient_checker import compute_gradient_error
7778
from tensorflow.python.ops.gradient_checker import compute_gradient
78-
# pylint: enable=unused-import
79+
# pylint: enable=unused-import,g-bad-import-order
7980

8081
import sys
8182
if sys.version_info.major == 2:

tensorflow/python/user_ops/user_ops.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@
1919
from __future__ import division
2020
from __future__ import print_function
2121

22-
from tensorflow.python.ops import gen_user_ops
23-
from tensorflow.python.ops.gen_user_ops import *
22+
from tensorflow.python.ops import gen_user_ops as _gen_user_ops
23+
24+
# go/tf-wildcard-import
25+
from tensorflow.python.ops.gen_user_ops import * # pylint: disable=wildcard-import
2426

2527

2628
def my_fact():
2729
"""Example of overriding the generated code for an Op."""
28-
return gen_user_ops._fact()
30+
return _gen_user_ops._fact() # pylint: disable=protected-access

tensorflow/python/util/all_util.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,7 @@ def reveal_undocumented(symbol_name, target_module=None):
8383

8484
def remove_undocumented(module_name, allowed_exception_list=None,
8585
doc_string_modules=None):
86-
"""Removes symbols in a module that are not referenced by a docstring that
87-
contributes to documentation.
86+
"""Removes symbols in a module that are not referenced by a docstring.
8887
8988
Args:
9089
module_name: the name of the module (usually `__name__`).
@@ -100,7 +99,7 @@ def remove_undocumented(module_name, allowed_exception_list=None,
10099
"""
101100
current_symbols = set(dir(_sys.modules[module_name]))
102101
should_have = make_all(module_name, doc_string_modules)
103-
should_have += allowed_exception_list
102+
should_have += allowed_exception_list or []
104103
extra_symbols = current_symbols - set(should_have)
105104
target_module = _sys.modules[module_name]
106105
for extra_symbol in extra_symbols:

tensorflow/tools/common/BUILD

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,22 @@ package(
99
default_visibility = ["//tensorflow:__subpackages__"],
1010
)
1111

12+
py_library(
13+
name = "public_api",
14+
srcs = ["public_api.py"],
15+
srcs_version = "PY2AND3",
16+
)
17+
18+
py_test(
19+
name = "public_api_test",
20+
srcs = ["public_api_test.py"],
21+
srcs_version = "PY2AND3",
22+
deps = [
23+
":public_api",
24+
"//tensorflow/python:platform_test",
25+
],
26+
)
27+
1228
py_library(
1329
name = "traverse",
1430
srcs = ["traverse.py"],
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# Copyright 2015 The TensorFlow Authors. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
# ==============================================================================
15+
"""Visitor restricting traversal to only the public tensorflow API."""
16+
17+
from __future__ import absolute_import
18+
from __future__ import division
19+
from __future__ import print_function
20+
21+
import inspect
22+
23+
24+
class PublicAPIVisitor(object):
25+
"""Visitor to use with `traverse` to visit exactly the public TF API."""
26+
27+
def __init__(self, visitor):
28+
"""Constructor.
29+
30+
`visitor` should be a callable suitable as a visitor for `traverse`. It will
31+
be called only for members of the public TensorFlow API.
32+
33+
Args:
34+
visitor: A visitor to call for the public API.
35+
"""
36+
self._visitor = visitor
37+
38+
# Modules/classes we do not want to descend into if we hit them. Usually,
39+
# sytem modules exposed through platforms for compatibility reasons.
40+
# Each entry maps a module path to a name to ignore in traversal.
41+
_do_not_descend_map = {
42+
# TODO(drpng): This can be removed once sealed off.
43+
'': ['platform', 'pywrap_tensorflow'],
44+
45+
# Some implementations have this internal module that we shouldn't expose.
46+
'flags': ['cpp_flags'],
47+
48+
# Everything below here is legitimate.
49+
'app': 'flags', # It'll stay, but it's not officially part of the API
50+
'test': ['mock'], # Imported for compatibility between py2/3.
51+
}
52+
53+
def _isprivate(self, name):
54+
"""Return whether a name is private."""
55+
return name.startswith('_')
56+
57+
def _do_not_descend(self, path, name):
58+
"""Safely queries if a specific fully qualified name should be excluded."""
59+
return (path in self._do_not_descend_map and
60+
name in self._do_not_descend_map[path])
61+
62+
def __call__(self, path, parent, children):
63+
"""Visitor interface, see `traverse` for details."""
64+
if inspect.ismodule(parent) and len(path.split('.')) > 10:
65+
raise RuntimeError('Modules nested too deep:\n%s\n\nThis is likely a '
66+
'problem with an accidental public import.' % path)
67+
68+
# Remove things that are not visible.
69+
for name, child in list(children):
70+
if self._isprivate(name):
71+
children.remove((name, child))
72+
73+
self._visitor(path, parent, children)
74+
75+
# Remove things that are visible, but which should not be descended into.
76+
for name, child in list(children):
77+
if self._do_not_descend(path, name):
78+
children.remove((name, child))
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Copyright 2015 The TensorFlow Authors. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
# ==============================================================================
15+
"""Tests for tensorflow.tools.common.public_api."""
16+
17+
from __future__ import absolute_import
18+
from __future__ import division
19+
from __future__ import print_function
20+
21+
from tensorflow.python.platform import googletest
22+
from tensorflow.tools.common import public_api
23+
24+
25+
class PublicApiTest(googletest.TestCase):
26+
27+
class TestVisitor(object):
28+
29+
def __init__(self):
30+
self.symbols = set()
31+
self.last_parent = None
32+
self.last_children = None
33+
34+
def __call__(self, path, parent, children):
35+
self.symbols.add(path)
36+
self.last_parent = parent
37+
self.last_children = list(children) # Make a copy to preserve state.
38+
39+
def test_call_forward(self):
40+
visitor = self.TestVisitor()
41+
children = [('name1', 'thing1'), ('name2', 'thing2')]
42+
public_api.PublicAPIVisitor(visitor)('test', 'dummy', children)
43+
self.assertEqual(set(['test']), visitor.symbols)
44+
self.assertEqual('dummy', visitor.last_parent)
45+
self.assertEqual([('name1', 'thing1'), ('name2', 'thing2')],
46+
visitor.last_children)
47+
48+
def test_private_child_removal(self):
49+
visitor = self.TestVisitor()
50+
children = [('name1', 'thing1'), ('_name2', 'thing2')]
51+
public_api.PublicAPIVisitor(visitor)('test', 'dummy', children)
52+
# Make sure the private symbols are removed before the visitor is called.
53+
self.assertEqual([('name1', 'thing1')], visitor.last_children)
54+
self.assertEqual([('name1', 'thing1')], children)
55+
56+
def test_no_descent_child_removal(self):
57+
visitor = self.TestVisitor()
58+
children = [('name1', 'thing1'), ('mock', 'thing2')]
59+
public_api.PublicAPIVisitor(visitor)('test', 'dummy', children)
60+
# Make sure not-to-be-descended-into symbols are removed after the visitor
61+
# is called.
62+
self.assertEqual([('name1', 'thing1'), ('mock', 'thing2')],
63+
visitor.last_children)
64+
self.assertEqual([('name1', 'thing1')], children)
65+
66+
67+
if __name__ == '__main__':
68+
googletest.main()

0 commit comments

Comments
 (0)