How to use the astroid.extract_node function in astroid

To help you get started, we’ve selected a few astroid 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 PyCQA / pylint / tests / extensions / test_check_docs.py View on Github external
def test_wrong_name_of_func_params_in_google_docstring(self):
        """Example of functions with inconsistent parameter names in the
        signature and in the Google style documentation
        """
        node = astroid.extract_node(
            """
        def function_foo(xarg, yarg, zarg):
            '''function foo ...

            Args:
                xarg1 (int): bla xarg
                yarg (float): bla yarg

                zarg1 (str): bla zarg
            '''
            return xarg + yarg
        """
        )
        with self.assertAddsMessages(
            Message(msg_id="missing-param-doc", node=node, args=("xarg, zarg",)),
            Message(msg_id="missing-type-doc", node=node, args=("xarg, zarg",)),
github PyCQA / pylint / tests / extensions / test_check_docs.py View on Github external
def test_finds_multiple_types_sphinx(self, complex_type):
        node = astroid.extract_node(
            '''
        def my_func(named_arg):
            """The docstring

            :param named_arg: Returned
            :type named_arg: {0}

            :returns: named_arg
            :rtype: {0}
            """
            return named_arg
        '''.format(
                complex_type
            )
        )
        with self.assertNoMessages():
github PyCQA / pylint / tests / extensions / test_check_docs.py View on Github external
def test_ignores_optional_specifier_google(self):
        node = astroid.extract_node(
            '''
        def do_something(param1, param2, param3=(), param4=[], param5=[], param6=True):
            """Do something.

            Args:
                param1 (str): Description.
                param2 (dict(str, int)): Description.
                param3 (tuple(str), optional): Defaults to empty. Description.
                param4 (List[str], optional): Defaults to empty. Description.
                param5 (list[tuple(str)], optional): Defaults to empty. Description.
                param6 (bool, optional): Defaults to True. Description.

            Returns:
                int: Description.
            """
            return param1, param2, param3, param4, param5, param6
github PyCQA / pylint / tests / unittest_checker_base.py View on Github external
def test_multi_name_detection_first_invalid(self):
        classes = astroid.extract_node(
            """
        class class_a(object): #@
            pass
        class classb(object): #@
            pass
        class CLASSC(object): #@
            pass
        """
        )
        messages = [
            Message(
                "invalid-name",
                node=classes[0],
                args=(
                    "Class",
                    "class_a",
github PyCQA / pylint / tests / unittest_checker_python3.py View on Github external
def test_valid_codec(self):
        node = astroid.extract_node('foobar.encode("ascii", "ignore")  #@')
        with self.assertNoMessages():
            self.checker.visit_call(node)
github PyCQA / pylint / tests / extensions / test_check_docs.py View on Github external
def test_wrong_name_of_func_params_in_numpy_docstring(self):
        """Example of functions with inconsistent parameter names in the
        signature and in the Numpy style documentation
        """
        node = astroid.extract_node(
            """
        def function_foo(xarg, yarg, zarg):
            '''function foo ...

            Parameters
            ----------
            xarg1: int
                bla xarg
            yarg: float
                bla yarg

            zarg1: str
                bla zarg
            '''
            return xarg + yarg
        """
github PyCQA / pylint / tests / extensions / test_check_docs.py View on Github external
def test_constr_params_in_init_numpy(self):
        """Example of a class with missing constructor parameter documentation
        (Numpy style)

        Everything is completely analogous to functions.
        """
        node = astroid.extract_node(
            """
        class ClassFoo(object):
            def __init__(self, x, y):
                '''docstring foo constructor

                Parameters
                ----------
                y:
                    bla

                missing constructor parameter documentation
                '''
                pass

        """
        )
github PyCQA / pylint / tests / extensions / test_check_yields_docs.py View on Github external
def test_warn_missing_google_yields(self):
        node = astroid.extract_node(
            '''
        def my_func(self, doc_type):
            """This is a docstring.

            Parameters:
                doc_type (str): Google
            """
            yield False
        '''
        )
        yield_node = node.body[0]
        with self.assertAddsMessages(
            Message(msg_id="missing-yield-doc", node=node),
            Message(msg_id="missing-yield-type-doc", node=node),
        ):
            self.checker.visit_yield(yield_node)
github PyCQA / pylint / tests / unittest_checker_python3.py View on Github external
def as_iterable_in_unpacking(self, fxn):
        node = astroid.extract_node(
            """
        a, b = __({}())
        """.format(
                fxn
            )
        )
        with self.assertNoMessages():
            self.checker.visit_call(node)
github BasPH / pylint-airflow / tests / pylint_airflow / checkers / test_operator.py View on Github external
def test_not_match_callable_taskid(self):
        """python_callable function name matches _[task_id], expect no message."""
        testcase = """
        from airflow.operators.python_operator import PythonOperator

        def _mytask():
            print("dosomething")

        mytask = PythonOperator(task_id="mytask", python_callable=_mytask) #@
        """

        assign_node = astroid.extract_node(testcase)
        with self.assertNoMessages():
            self.checker.visit_assign(assign_node)