Converts an entity into an equivalent entity.
(entity, program_ctx)
| 304 | |
| 305 | |
| 306 | def convert(entity, program_ctx): |
| 307 | """Converts an entity into an equivalent entity.""" |
| 308 | |
| 309 | if tf_inspect.isfunction(entity) or tf_inspect.ismethod(entity): |
| 310 | free_nonglobal_var_names = entity.__code__.co_freevars |
| 311 | else: |
| 312 | free_nonglobal_var_names = () |
| 313 | |
| 314 | for i, name in enumerate(free_nonglobal_var_names): |
| 315 | if (name == 'ag__' and |
| 316 | entity.__closure__[i].cell_contents is not ag_internal): |
| 317 | raise ValueError('entity {} uses the reserved symbol "{}"'.format( |
| 318 | entity, name)) |
| 319 | # TODO(mdan): In extreme cases, other ag__ symbols may also be clobbered. |
| 320 | |
| 321 | converted_entity_info = _convert_with_cache(entity, program_ctx, |
| 322 | free_nonglobal_var_names) |
| 323 | |
| 324 | return _instantiate(entity, converted_entity_info, free_nonglobal_var_names) |
| 325 | |
| 326 | |
| 327 | # TODO(mdan): allow_namedtuple_subclass should be hardcoded to True. |
nothing calls this directly
no test coverage detected