'Context manager that handles graph, namescope, and nested blocks.'

@contextlib.contextmanager
def _BlockScope(self):

    self._stack.append(self)
    try:
        with self._graph.as_default():
            with self._OptionalNameScope(self._scope_str):
                (yield self)
    finally:
        self._stack.pop()
