Add a quick note about accessing a function's namespace.
PiperOrigin-RevId: 307494941 Change-Id: I6b0de38c1f01c3878ec69fe2773af64fffab079e
This commit is contained in:
parent
e3d54be705
commit
7c5934dfd9
@ -153,7 +153,11 @@
|
|||||||
"id": "kuT7J-xps_2Y"
|
"id": "kuT7J-xps_2Y"
|
||||||
},
|
},
|
||||||
"source": [
|
"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": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
|
"from tensorflow.python.autograph.pyct import inspect_utils\n",
|
||||||
|
"\n",
|
||||||
"f_info = transformer.EntityInfo(\n",
|
"f_info = transformer.EntityInfo(\n",
|
||||||
" name='f',\n",
|
" name='f',\n",
|
||||||
" source_code=source,\n",
|
" source_code=source,\n",
|
||||||
" source_file=None,\n",
|
" source_file=None,\n",
|
||||||
" future_features=(),\n",
|
" future_features=(),\n",
|
||||||
" namespace=None)\n",
|
" namespace=inspect_utils.getnamespace(f))\n",
|
||||||
"ctx = transformer.Context(f_info, None, None)"
|
"ctx = transformer.Context(f_info, None, None)"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user