本文整理匯總了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