Delay transpiler initialzation to mitigate effects of circular imports.

PiperOrigin-RevId: 350787978
Change-Id: I134b53638c8c3c959724b713c5c517b6330b2546
This commit is contained in:
Dan Moldovan 2021-01-08 10:19:19 -08:00 committed by TensorFlower Gardener
parent c584ef0ee7
commit d2f068134d
2 changed files with 21 additions and 20 deletions

View File

@ -334,7 +334,7 @@ _AG_FIXED_RETURN_TYPE = {
QN = qual_names.QN QN = qual_names.QN
# TODO(mdan): Fix this with an importable module. # TODO(mdan): Fix this with an importable module.
AG_MODULE = api._TRANSPILER._extra_locals['ag__'] # pylint:disable=protected-access AG_MODULE = api._TRANSPILER.get_extra_locals()['ag__'] # pylint:disable=protected-access
class TFRTypeResolver(type_inference.Resolver): class TFRTypeResolver(type_inference.Resolver):

View File

@ -209,7 +209,13 @@ class PyToTF(transpiler.PyToPy):
def __init__(self): def __init__(self):
super(PyToTF, self).__init__() super(PyToTF, self).__init__()
self._extra_locals = None
def get_transformed_name(self, node):
return 'tf__' + super(PyToTF, self).get_transformed_name(node)
def get_extra_locals(self):
if self._extra_locals is None:
# TODO(mdan): Move into core or replace with an actual importable module. # TODO(mdan): Move into core or replace with an actual importable module.
# Craft a module that exposes the external API as well as certain # Craft a module that exposes the external API as well as certain
# internal modules. # internal modules.
@ -228,11 +234,6 @@ class PyToTF(transpiler.PyToPy):
ag_internal.__dict__.update(operators.__dict__) ag_internal.__dict__.update(operators.__dict__)
self._extra_locals = {'ag__': ag_internal} self._extra_locals = {'ag__': ag_internal}
def get_transformed_name(self, node):
return 'tf__' + super(PyToTF, self).get_transformed_name(node)
def get_extra_locals(self):
return self._extra_locals return self._extra_locals
def get_caching_key(self, ctx): def get_caching_key(self, ctx):