Add tf.print an an alias for tf.Print (#19234)
Users with Python 3 or `from __future__ import print_function` can now use lowercase `tf.print`. `create_python_api.py` needed some adjustment to ensure that `print_function` doesn't appear as part of the API. Fixes #18053.
This commit is contained in:
parent
d8f9538ab4
commit
9b41e5158e
@ -35,8 +35,9 @@ from tensorflow.python.util.tf_export import tf_export
|
||||
|
||||
|
||||
# Assert and Print are special symbols in python, so we must
|
||||
# use an upper-case version of them.
|
||||
@tf_export("Print")
|
||||
# have an upper-case version of them. For users with Python 3 or Python 2.7
|
||||
# with `from __future__ import print_function`, we also allow lowercase.
|
||||
@tf_export("Print", "print")
|
||||
def Print(input_, data, message=None, first_n=None, summarize=None,
|
||||
name=None):
|
||||
"""Prints a list of tensors.
|
||||
|
@ -37,7 +37,11 @@ _GENERATED_FILE_HEADER = """\"\"\"Imports for Python API.
|
||||
This file is MACHINE GENERATED! Do not edit.
|
||||
Generated by: tensorflow/tools/api/generator/create_python_api.py script.
|
||||
\"\"\"
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
"""
|
||||
_GENERATED_FILE_FOOTER = "\n\ndel print_function\n"
|
||||
|
||||
|
||||
class SymbolExposedTwiceError(Exception):
|
||||
@ -145,6 +149,7 @@ class _ModuleInitCodeBuilder(object):
|
||||
_names_with_underscore = [%s]
|
||||
__all__ = [s for s in dir() if not s.startswith('_')]
|
||||
__all__.extend([s for s in _names_with_underscore])
|
||||
__all__.remove('print_function')
|
||||
''' % underscore_names_str
|
||||
|
||||
return module_text_map
|
||||
@ -270,7 +275,7 @@ def create_api_files(output_files, package):
|
||||
missing_output_files.append(module_file_path)
|
||||
continue
|
||||
with open(module_name_to_file_path[module], 'w') as fp:
|
||||
fp.write(_GENERATED_FILE_HEADER + text)
|
||||
fp.write(_GENERATED_FILE_HEADER + text + _GENERATED_FILE_FOOTER)
|
||||
|
||||
if missing_output_files:
|
||||
raise ValueError(
|
||||
|
@ -1532,6 +1532,10 @@ tf_module {
|
||||
name: "pow"
|
||||
argspec: "args=[\'x\', \'y\', \'name\'], varargs=None, keywords=None, defaults=[\'None\'], "
|
||||
}
|
||||
member_method {
|
||||
name: "print"
|
||||
argspec: "args=[\'input_\', \'data\', \'message\', \'first_n\', \'summarize\', \'name\'], varargs=None, keywords=None, defaults=[\'None\', \'None\', \'None\', \'None\'], "
|
||||
}
|
||||
member_method {
|
||||
name: "py_func"
|
||||
argspec: "args=[\'func\', \'inp\', \'Tout\', \'stateful\', \'name\'], varargs=None, keywords=None, defaults=[\'True\', \'None\'], "
|
||||
|
Loading…
x
Reference in New Issue
Block a user