def _check_lambda_inside_loop( self, node: Union[AnyLoop, AnyComprehension], ) -> None: for lambda_node in walk.get_subnodes_by_type(node, ast.Lambda): arg_nodes = walk.get_subnodes_by_type(lambda_node, ast.arg) body_nodes = walk.get_subnodes_by_type(lambda_node.body, ast.Name) arguments = (arg.arg for arg in arg_nodes) body = (subnode.id for subnode in body_nodes) if not all(symbol in arguments for symbol in body): self.add_violation(LambdaInsideLoopViolation(node))
def _check_lambda_inside_loop( self, node: Union[AnyLoop, AnyComprehension], ) -> None: container_names = self._containers.get(type(node), ()) for container in container_names: body = getattr(node, container, []) if not isinstance(body, list): body = [body] for subnode in body: if walk.is_contained(subnode, ast.Lambda): self.add_violation(LambdaInsideLoopViolation(node))
def _check_lambda_inside_loop(self, node: AnyLoop) -> None: for subnode in node.body: if is_contained(subnode, (ast.Lambda, )): self.add_violation(LambdaInsideLoopViolation(node))