How to use the dlint.tree.walk_callback_same_scope function in dlint

To help you get started, we’ve selected a few dlint examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github duo-labs / dlint / dlint / linters / twisted / yield_return_statement.py View on Github external
self.generic_visit(node)

        # https://twistedmatrix.com/documents/17.1.0/api/twisted.internet.defer.inlineCallbacks.html
        is_python_3_3 = sys.version_info >= (3, 3)

        if (is_python_3_3
                or not tree.function_has_inlinecallbacks_decorator(node)):
            return

        results = []

        def return_statement_callback(inner_node):
            if isinstance(inner_node, ast.Return) and tree.non_empty_return(inner_node):
                results.append(inner_node)

        tree.walk_callback_same_scope(node, return_statement_callback)

        self.results.extend([
            base.Flake8Result(
                lineno=result.lineno,
                col_offset=result.col_offset,
                message=self._error_tmpl
            )
            for result in results
        ])
github duo-labs / dlint / dlint / linters / twisted / returnvalue_in_inlinecallbacks.py View on Github external
def visit_FunctionDef(self, node):
        self.generic_visit(node)

        if tree.function_has_inlinecallbacks_decorator(node):
            return

        results = []

        def returnvalue_statement_callback(inner_node):
            if isinstance(inner_node, ast.Call) and tree.call_is_returnvalue(inner_node.func):
                results.append(inner_node)

        tree.walk_callback_same_scope(node, returnvalue_statement_callback)

        if results:
            self.results.append(
                base.Flake8Result(
                    lineno=node.lineno,
                    col_offset=node.col_offset,
                    message=self._error_tmpl
                )
github duo-labs / dlint / dlint / linters / twisted / inlinecallbacks_yield_statement.py View on Github external
def visit_FunctionDef(self, node):
        self.generic_visit(node)

        if not tree.function_has_inlinecallbacks_decorator(node):
            return

        if tree.function_is_empty(node):
            return

        results = []

        def yield_statement_callback(inner_node):
            if isinstance(inner_node, ast.Yield):
                results.append(inner_node)

        tree.walk_callback_same_scope(node, yield_statement_callback)

        if not results:
            self.results.append(
                base.Flake8Result(
                    lineno=node.lineno,
                    col_offset=node.col_offset,
                    message=self._error_tmpl
                )
github duo-labs / dlint / dlint / linters / helpers / bad_name_attribute_use.py View on Github external
try:
                latest_variable_assignment = max(
                    [
                        target for target in targets
                        if target.variable == variable
                    ],
                    key=lambda target: (target.lineno, target.col_offset)
                )
            except ValueError:
                # No variable name matches
                return

            if latest_variable_assignment in illegal_calls:
                results.append(inner_node)

        tree.walk_callback_same_scope(node, attribute_use_callback)

        self.results.extend([
            base.Flake8Result(
                lineno=result.lineno,
                col_offset=result.col_offset,
                message=self._error_tmpl
            )
            for result in results
        ])
github duo-labs / dlint / dlint / linters / helpers / bad_name_attribute_use.py View on Github external
and isinstance(inner_node.value, ast.Call)):
                return

            module_path = tree.module_path_str(inner_node.value.func)
            targets.extend([
                Assignment(
                    variable=target.id,
                    module_path=module_path,
                    lineno=inner_node.lineno,
                    col_offset=inner_node.col_offset,
                )
                for target in inner_node.targets
                if isinstance(target, ast.Name)
            ])

        tree.walk_callback_same_scope(node, variable_assignment_callback)

        results = []

        def attribute_use_callback(inner_node):
            if not (isinstance(inner_node, ast.Call)
                    and isinstance(inner_node.func, ast.Attribute)
                    and isinstance(inner_node.func.value, ast.Name)):
                return

            variable = inner_node.func.value.id
            attribute = inner_node.func.attr

            illegal_calls = [
                target for target in targets
                if target.variable == variable
                and attribute in self.illegal_name_attributes