當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。