Python ast 模块,YieldFrom() 实例源码

我们从Python开源项目中,提取了以下7个代码示例,用于说明如何使用ast.YieldFrom()

项目:flake8-bugbear    作者:PyCQA    | 项目源码 | 文件源码
def check_for_b901(self, node):
        xs = list(node.body)
        has_yield = False
        return_node = None
        while xs:
            x = xs.pop()
            if isinstance(x, (ast.AsyncFunctionDef, ast.FunctionDef)):
                continue
            elif isinstance(x, (ast.Yield, ast.YieldFrom)):
                has_yield = True
            elif isinstance(x, ast.Return) and x.value is not None:
                return_node = x

            if has_yield and return_node is not None:
                self.errors.append(
                    B901(return_node.lineno, return_node.col_offset)
                )
                break

            xs.extend(ast.iter_child_nodes(x))
项目:opyum    作者:Amper    | 项目源码 | 文件源码
def visit_For(self, node: ast.For):
        node = self.generic_visit(node)
        if self._is_for_yield(node):
            yield_node = ast.YieldFrom(value = node.iter)
            expr_node = ast.Expr(value = yield_node)
            node = ast.copy_location(expr_node, node)
            node = ast.fix_missing_locations(node)
        return node
项目:web_ctp    作者:molebot    | 项目源码 | 文件源码
def test_yield(self):
        self.expr(ast.Yield(ast.Name("x", ast.Store())), "must have Load")
        self.expr(ast.YieldFrom(ast.Name("x", ast.Store())), "must have Load")
项目:ouroboros    作者:pybee    | 项目源码 | 文件源码
def test_yield(self):
        self.expr(ast.Yield(ast.Name("x", ast.Store())), "must have Load")
        self.expr(ast.YieldFrom(ast.Name("x", ast.Store())), "must have Load")
项目:kbe_server    作者:xiaohaoppy    | 项目源码 | 文件源码
def test_yield(self):
        self.expr(ast.Yield(ast.Name("x", ast.Store())), "must have Load")
        self.expr(ast.YieldFrom(ast.Name("x", ast.Store())), "must have Load")
项目:metapensiero.pj    作者:azazel75    | 项目源码 | 文件源码
def _isyield(el):
    return isinstance(el, (ast.Yield, ast.YieldFrom))
项目:peval    作者:fjarri    | 项目源码 | 文件源码
def is_a_generator(function):
    return has_nodes(function.tree, (ast.Yield, ast.YieldFrom))