Skip to content

Commit f6cdf20

Browse files
committed
use isnewscope
1 parent dbd1ba4 commit f6cdf20

1 file changed

Lines changed: 3 additions & 6 deletions

File tree

unpythonic/syntax/tests/test_conts_multishot.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
from mcpyrate.walkers import ASTTransformer
4747

4848
from unpythonic.syntax import get_cc, iscontinuation
49+
from unpythonic.syntax.scopeanalyzer import isnewscope
4950

5051
def myield_function(tree, syntax, **kw):
5152
"""[syntax, name/expr] Yield from a multi-shot generator.
@@ -197,9 +198,7 @@ class MultishotYieldTransformer(ASTTransformer):
197198
def transform(self, tree):
198199
if is_captured_value(tree): # do not recurse into hygienic captures
199200
return tree
200-
# respect scope boundaries
201-
if type(tree) in (ast.FunctionDef, ast.AsyncFunctionDef, ast.ClassDef,
202-
ast.ListComp, ast.DictComp, ast.SetComp, ast.GeneratorExp):
201+
if isnewscope(tree): # respect scope boundaries
203202
return tree
204203

205204
# `k = myield[value]`
@@ -263,9 +262,7 @@ class ReturnToRaiseStopIterationTransformer(ASTTransformer):
263262
def transform(self, tree):
264263
if is_captured_value(tree): # do not recurse into hygienic captures
265264
return tree
266-
# respect scope boundaries
267-
if type(tree) in (ast.FunctionDef, ast.AsyncFunctionDef, ast.ClassDef,
268-
ast.ListComp, ast.DictComp, ast.SetComp, ast.GeneratorExp):
265+
if isnewscope(tree): # respect scope boundaries
269266
return tree
270267

271268
if type(tree) is ast.Return:

0 commit comments

Comments
 (0)