当前位置: 首页>>代码示例>>Python>>正文


Python ast.YieldFrom方法代码示例

本文整理汇总了Python中ast.YieldFrom方法的典型用法代码示例。如果您正苦于以下问题:Python ast.YieldFrom方法的具体用法?Python ast.YieldFrom怎么用?Python ast.YieldFrom使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ast的用法示例。


在下文中一共展示了ast.YieldFrom方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: check_for_b901

# 需要导入模块: import ast [as 别名]
# 或者: from ast import YieldFrom [as 别名]
def check_for_b901(self, node):
        if node.name == "__await__":
            return

        has_yield = False
        return_node = None

        for parent, x in self.walk_function_body(node):
            # Only consider yield when it is part of an Expr statement.
            if isinstance(parent, ast.Expr) and isinstance(
                x, (ast.Yield, ast.YieldFrom)
            ):
                has_yield = True

            if 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 
开发者ID:PyCQA,项目名称:flake8-bugbear,代码行数:22,代码来源:bugbear.py

示例2: _visit_yield_from

# 需要导入模块: import ast [as 别名]
# 或者: from ast import YieldFrom [as 别名]
def _visit_yield_from(self: 'ASTTagger', node: ast.YieldFrom):
    self.symtable.cts.add(ContextType.Generator)
    return node 
开发者ID:Xython,项目名称:YAPyPy,代码行数:5,代码来源:symbol_analyzer.py

示例3: _has_yield

# 需要导入模块: import ast [as 别名]
# 或者: from ast import YieldFrom [as 别名]
def _has_yield(fun):  # type: (Union[ast.FunctionDef, ast.AsyncFunctionDef]) -> bool  # noqa: E501
    for node in ast.walk(fun):
        if isinstance(node, ast.Yield) or isinstance(node, ast.YieldFrom):
            return True
    return False 
开发者ID:terrencepreilly,项目名称:darglint,代码行数:7,代码来源:function_description.py

示例4: test_yield

# 需要导入模块: import ast [as 别名]
# 或者: from ast import YieldFrom [as 别名]
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") 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:5,代码来源:test_ast.py

示例5: translate_yield_from

# 需要导入模块: import ast [as 别名]
# 或者: from ast import YieldFrom [as 别名]
def translate_yield_from(self, exp):
        if len(exp) != 2:
            raise MochiSyntaxError(exp, self.filename)

        pre, value = self.translate(exp[1], False)
        if type(value) is ast.Expr:
            value = value.value
        yield_from_node = ast.YieldFrom(value=value,
                                        lineno=exp[0].lineno,
                                        col_offset=0)
        return pre, yield_from_node 
开发者ID:i2y,项目名称:mochi,代码行数:13,代码来源:translation.py

示例6: _check_method_contents

# 需要导入模块: import ast [as 别名]
# 或者: from ast import YieldFrom [as 别名]
def _check_method_contents(self, node: types.AnyFunctionDef) -> None:
        if node.name in constants.YIELD_MAGIC_METHODS_BLACKLIST:
            if walk.is_contained(node, (ast.Yield, ast.YieldFrom)):
                self.add_violation(oop.YieldMagicMethodViolation(node)) 
开发者ID:wemake-services,项目名称:wemake-python-styleguide,代码行数:6,代码来源:classes.py

示例7: visit_YieldFrom

# 需要导入模块: import ast [as 别名]
# 或者: from ast import YieldFrom [as 别名]
def visit_YieldFrom(self, node: ast.YieldFrom) -> None:
        """
        Visits `yield from` nodes.

        Raises:
            IncorrectYieldFromTargetViolation

        """
        self._check_yield_from_type(node)
        self._check_yield_from_empty(node)
        self.generic_visit(node) 
开发者ID:wemake-services,项目名称:wemake-python-styleguide,代码行数:13,代码来源:keywords.py

示例8: _check_yield_from_type

# 需要导入模块: import ast [as 别名]
# 或者: from ast import YieldFrom [as 别名]
def _check_yield_from_type(self, node: ast.YieldFrom) -> None:
        if not isinstance(node.value, self._allowed_nodes):
            self.add_violation(IncorrectYieldFromTargetViolation(node)) 
开发者ID:wemake-services,项目名称:wemake-python-styleguide,代码行数:5,代码来源:keywords.py

示例9: _check_yield_from_empty

# 需要导入模块: import ast [as 别名]
# 或者: from ast import YieldFrom [as 别名]
def _check_yield_from_empty(self, node: ast.YieldFrom) -> None:
        if isinstance(node.value, ast.Tuple):
            if not node.value.elts:
                self.add_violation(IncorrectYieldFromTargetViolation(node)) 
开发者ID:wemake-services,项目名称:wemake-python-styleguide,代码行数:6,代码来源:keywords.py

示例10: is_generator

# 需要导入模块: import ast [as 别名]
# 或者: from ast import YieldFrom [as 别名]
def is_generator(node: AnyFunctionDef) -> bool:
    """Tells whether a given function is a generator."""
    for body_item in node.body:
        if is_contained(node=body_item, to_check=(Yield, YieldFrom)):
            return True
    return False 
开发者ID:wemake-services,项目名称:wemake-python-styleguide,代码行数:8,代码来源:functions.py


注:本文中的ast.YieldFrom方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。