@@ -86,8 +86,7 @@ def __init__(self, hub, layer):
86
86
87
87
def __enter__ (self ):
88
88
scope = self ._layer [1 ]
89
- if scope is None :
90
- scope = Scope ()
89
+ assert scope is not None
91
90
return scope
92
91
93
92
def __exit__ (self , exc_type , exc_value , tb ):
@@ -271,21 +270,24 @@ def push_scope(self, callback=None):
271
270
that should be used to pop the scope again. Alternatively a callback
272
271
can be provided that is executed in the context of the scope.
273
272
"""
273
+ if callback is not None :
274
+ with self .push_scope () as scope :
275
+ callback (scope )
276
+ return
277
+
274
278
client , scope = self ._stack [- 1 ]
275
279
new_layer = (client , copy .copy (scope ))
276
280
self ._stack .append (new_layer )
277
281
278
- if callback is not None :
279
- if client is not None :
280
- callback (scope )
281
- else :
282
- return _ScopeManager (self , new_layer )
282
+ return _ScopeManager (self , new_layer )
283
+
284
+ scope = push_scope
283
285
284
286
def pop_scope_unsafe (self ):
285
287
"""Pops a scope layer from the stack. Try to use the context manager
286
288
`push_scope()` instead."""
287
289
rv = self ._stack .pop ()
288
- assert self ._stack
290
+ assert self ._stack , "stack must have at least one layer"
289
291
return rv
290
292
291
293
def configure_scope (self , callback = None ):
@@ -305,16 +307,6 @@ def inner():
305
307
306
308
return inner ()
307
309
308
- def scope (self , callback = None ):
309
- """Pushes a new scope and yields it for configuration.
310
-
311
- The scope is dropped at the end of the with statement. Alternatively
312
- a callback can be provided similar to `configure_scope`.
313
- """
314
- with self .push_scope ():
315
- client , scope = self ._stack [- 1 ]
316
- return self .configure_scope (callback )
317
-
318
310
319
311
GLOBAL_HUB = Hub ()
320
312
_local .set (GLOBAL_HUB )
0 commit comments