Add a quick note about accessing a function's namespace.

PiperOrigin-RevId: 307494941
Change-Id: I6b0de38c1f01c3878ec69fe2773af64fffab079e
This commit is contained in:
Dan Moldovan 2020-04-20 16:03:05 -07:00 committed by TensorFlower Gardener
parent e3d54be705
commit 7c5934dfd9

View File

@ -153,7 +153,11 @@
"id": "kuT7J-xps_2Y"
},
"source": [
"There are a couple of context objects that most transformer objects like `CodeGenerator` use:"
"There are a couple of context objects that most transformer objects like `CodeGenerator` use.\n",
"\n",
"Of note here is `EntityInfo.namespace`, which contains the runtime values for all the global and closure names that the function has access to. Inside a transformer object, this is available under `self.ctx.info.namespace`.\n",
"\n",
"For example, if a function uses NumPy, its namespace will typically include `'np'`."
]
},
{
@ -166,12 +170,14 @@
},
"outputs": [],
"source": [
"from tensorflow.python.autograph.pyct import inspect_utils\n",
"\n",
"f_info = transformer.EntityInfo(\n",
" name='f',\n",
" source_code=source,\n",
" source_file=None,\n",
" future_features=(),\n",
" namespace=None)\n",
" namespace=inspect_utils.getnamespace(f))\n",
"ctx = transformer.Context(f_info, None, None)"
]
},