def _check_nested_function(self, node: AnyFunctionDef) -> None:
        is_inside_function = isinstance(get_context(node), FunctionNodes)

        is_direct = isinstance(get_parent(node), FunctionNodes)
        is_bad = is_direct and node.name not in NESTED_FUNCTIONS_WHITELIST

        if is_bad or (is_inside_function and not is_direct):
            self.add_violation(NestedFunctionViolation(node, text=node.name))
    def visit_Lambda(self, node: ast.Lambda) -> None:
        """
        Used to find nested ``lambda`` functions.

        Raises:
            NestedFunctionViolation

        """
        parent = getattr(node, 'parent', None)
        if isinstance(parent, ast.Lambda):
            self.add_violation(NestedFunctionViolation(node))
        self.generic_visit(node)
    def visit_FunctionDef(self, node: ast.FunctionDef) -> None:
        """
        Used to find nested functions.

        Uses ``NESTED_FUNCTIONS_WHITELIST`` to respect some nested functions.
        Respected usecases for nested functions:

        1. decorator
        2. factory function

        Raises:
            NestedFunctionViolation

        """
        parent = getattr(node, 'parent', None)
        is_inside_function = isinstance(parent, ast.FunctionDef)

        if is_inside_function and node.name not in NESTED_FUNCTIONS_WHITELIST:
            self.add_violation(NestedFunctionViolation(node, text=node.name))
        self.generic_visit(node)
    def _check_nested_lambdas(self, node: ast.Lambda) -> None:
        is_direct = isinstance(get_context(node), ast.Lambda)
        is_deep = is_child_of(node, ast.Lambda)

        if is_direct or is_deep:
            self.add_violation(NestedFunctionViolation(node, text='lambda'))
 def _check_nested_lambdas(self, node: ast.Lambda) -> None:
     parent = getattr(node, 'parent', None)
     if isinstance(parent, ast.Lambda):
         self.add_violation(NestedFunctionViolation(node))
    def _check_nested_function(self, node: AnyFunctionDef) -> None:
        parent = getattr(node, 'parent', None)
        is_inside_function = isinstance(parent, self._function_nodes)

        if is_inside_function and node.name not in NESTED_FUNCTIONS_WHITELIST:
            self.add_violation(NestedFunctionViolation(node, text=node.name))
 def _check_nested_lambdas(self, node: ast.Lambda) -> None:
     if isinstance(get_parent(node), ast.Lambda):
         self.add_violation(NestedFunctionViolation(node, text='lambda'))