本文整理汇总了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
示例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
示例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
示例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")
示例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
示例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))
示例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)
示例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))
示例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))
示例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