diff options
author | Charles Nicholson <nicholsonc@google.com> | 2017-04-21 10:59:14 -0800 |
---|---|---|
committer | TensorFlower Gardener <gardener@tensorflow.org> | 2017-04-21 12:09:42 -0700 |
commit | 8e5041918f2e709ded94e63fb1779d6bb363becb (patch) | |
tree | 5ec03d51d2e15b1247b68298b2ccd9138075513e /tensorflow/contrib/specs | |
parent | c3bf39b7a6c3cc41f209ac863c764498b503d4f5 (diff) |
Introduce TFDecorator, a base class for Python TensorFlow decorators. Provides basic introspection and "unwrap" services, allowing tooling code to fully 'understand' the wrapped object.
Change: 153854044
Diffstat (limited to 'tensorflow/contrib/specs')
-rw-r--r-- | tensorflow/contrib/specs/python/specs.py | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/tensorflow/contrib/specs/python/specs.py b/tensorflow/contrib/specs/python/specs.py index a9fba442db..d5223b9b55 100644 --- a/tensorflow/contrib/specs/python/specs.py +++ b/tensorflow/contrib/specs/python/specs.py @@ -19,13 +19,11 @@ from __future__ import absolute_import from __future__ import division from __future__ import print_function - -import inspect - from six import exec_ from tensorflow.contrib.specs.python import params_ops from tensorflow.contrib.specs.python import specs_lib from tensorflow.contrib.specs.python import specs_ops +from tensorflow.python.util import tf_inspect def eval_params(params, environment=None): @@ -44,7 +42,8 @@ def eval_params(params, environment=None): """ specs_lib.check_keywords(params) bindings = {} - if environment: bindings.update(environment) + if environment: + bindings.update(environment) exec_(params, vars(params_ops), bindings) # pylint: disable=exec-used return bindings @@ -71,7 +70,8 @@ def eval_spec(spec, environment=None): """ specs_lib.check_keywords(spec) bindings = {} - if environment: bindings.update(environment) + if environment: + bindings.update(environment) exec_(spec, vars(specs_ops), bindings) # pylint: disable=exec-used return bindings @@ -141,7 +141,7 @@ class LocalImport(object): self.names = names def __enter__(self): - self.frame = inspect.currentframe() + self.frame = tf_inspect.currentframe() bindings = self.frame.f_back.f_globals self.old = {k: bindings.get(k, None) for k in self.names.keys()} bindings.update(self.names) @@ -151,7 +151,9 @@ class LocalImport(object): bindings = self.frame.f_back.f_globals bindings.update(self.old) for k, v in self.old.items(): - if v is None: del bindings[k] + if v is None: + del bindings[k] del self.frame + ops = LocalImport(specs_ops) |