(self)
| 3030 | return self |
| 3031 | |
| 3032 | def __enter__(self): |
| 3033 | # If the default graph is building a function, then we should not replace it |
| 3034 | # with the cached graph. |
| 3035 | if ops.get_default_graph().building_function: |
| 3036 | self._building_function = True |
| 3037 | else: |
| 3038 | self._building_function = False |
| 3039 | if self._in_graph_mode and not self._building_function: |
| 3040 | self._graph_context_manager = self._graph.as_default() |
| 3041 | self._graph_context_manager.__enter__() |
| 3042 | if self._cached_pure_variable_scope is not None: |
| 3043 | # Fast path for re-entering variable_scopes. We've held on to the pure |
| 3044 | # variable scope from a previous successful __enter__, so we avoid some |
| 3045 | # overhead by re-using that object. |
| 3046 | if self._current_name_scope is not None: |
| 3047 | self._current_name_scope.__enter__() |
| 3048 | return self._cached_pure_variable_scope.__enter__() |
| 3049 | |
| 3050 | try: |
| 3051 | return self._enter_scope_uncached() |
| 3052 | except: |
| 3053 | if (self._in_graph_mode and not self._building_function and |
| 3054 | self._graph_context_manager is not None): |
| 3055 | self._graph_context_manager.__exit__(*sys.exc_info()) |
| 3056 | raise |
| 3057 | |
| 3058 | def _enter_scope_uncached(self): |
| 3059 | """Enters the context manager when there is no cached scope yet. |
no test coverage detected