From 8e5041918f2e709ded94e63fb1779d6bb363becb Mon Sep 17 00:00:00 2001 From: Charles Nicholson Date: Fri, 21 Apr 2017 10:59:14 -0800 Subject: 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 --- tensorflow/contrib/specs/python/specs.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'tensorflow/contrib/specs') 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) -- cgit v1.2.3