Python ast.YieldFrom() Examples
The following are 12
code examples of ast.YieldFrom().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
ast
, or try the search function
.
Example #1
Source File: bugbear.py From flake8-bugbear with MIT License | 6 votes |
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
Example #2
Source File: symbol_analyzer.py From YAPyPy with MIT License | 5 votes |
def _visit_yield_from(self: 'ASTTagger', node: ast.YieldFrom): self.symtable.cts.add(ContextType.Generator) return node
Example #3
Source File: function_description.py From darglint with MIT License | 5 votes |
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
Example #4
Source File: test_ast.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
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")
Example #5
Source File: test_ast.py From ironpython3 with Apache License 2.0 | 5 votes |
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")
Example #6
Source File: test_ast.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
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")
Example #7
Source File: translation.py From mochi with MIT License | 5 votes |
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
Example #8
Source File: classes.py From wemake-python-styleguide with MIT License | 5 votes |
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))
Example #9
Source File: keywords.py From wemake-python-styleguide with MIT License | 5 votes |
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)
Example #10
Source File: keywords.py From wemake-python-styleguide with MIT License | 5 votes |
def _check_yield_from_type(self, node: ast.YieldFrom) -> None: if not isinstance(node.value, self._allowed_nodes): self.add_violation(IncorrectYieldFromTargetViolation(node))
Example #11
Source File: keywords.py From wemake-python-styleguide with MIT License | 5 votes |
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))
Example #12
Source File: functions.py From wemake-python-styleguide with MIT License | 5 votes |
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