|
46 | 46 | from mcpyrate.walkers import ASTTransformer |
47 | 47 |
|
48 | 48 | from unpythonic.syntax import get_cc, iscontinuation |
| 49 | + from unpythonic.syntax.scopeanalyzer import isnewscope |
49 | 50 |
|
50 | 51 | def myield_function(tree, syntax, **kw): |
51 | 52 | """[syntax, name/expr] Yield from a multi-shot generator. |
@@ -197,9 +198,7 @@ class MultishotYieldTransformer(ASTTransformer): |
197 | 198 | def transform(self, tree): |
198 | 199 | if is_captured_value(tree): # do not recurse into hygienic captures |
199 | 200 | 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 |
203 | 202 | return tree |
204 | 203 |
|
205 | 204 | # `k = myield[value]` |
@@ -263,9 +262,7 @@ class ReturnToRaiseStopIterationTransformer(ASTTransformer): |
263 | 262 | def transform(self, tree): |
264 | 263 | if is_captured_value(tree): # do not recurse into hygienic captures |
265 | 264 | 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 |
269 | 266 | return tree |
270 | 267 |
|
271 | 268 | if type(tree) is ast.Return: |
|
0 commit comments