Cloud Defense Logo

Products

Solutions

Company

Book A Live Demo

Top 10 Examples of "pylint in functional component" in Python

Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'pylint' in functional components in Python. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.

    @check_messages("found-percent-in-_")
    def visit_binop(self, node):
        if node.op != "%":
            return

        curr = node
        while curr.parent:
            if isinstance(curr.parent, astroid.CallFunc) and getattr(curr.parent.func, "name", "") in translationMethods:
                self.add_message("W9901", node=node)
                break

            curr = curr.parent
def test_relative_from_import(self):
        node = test_utils.extract_node('from os import path  #@')
        message = testutils.Message('no-absolute-import', node=node)
        with self.assertAddsMessages(message):
            self.checker.visit_import(node)
'''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",)),
            Message(msg_id="differing-param-doc", node=node, args=("xarg1, zarg1",)),
            Message(msg_id="differing-type-doc", node=node, args=("xarg1, zarg1",)),
        ):
            self.checker.visit_functiondef(node)

        node = astroid.extract_node(
            """
        def function_foo(xarg, yarg):
            '''function foo ...

            Args:
                yarg1 (float): bla yarg

            For the other parameters, see bla.
            '''
            return xarg + yarg
        """
        )
def my_func(self):
            """This is a docstring.

            :raises NameError: Never
            """
            def ex_func(val):
                def inner_func(value):
                    return OSError(value)
                return RuntimeError(val)
            raise ex_func('hi') #@
            raise NameError('hi')
        '''
        )
        node = raise_node.frame()
        with self.assertAddsMessages(
            Message(msg_id="missing-raises-doc", node=node, args=("RuntimeError",))
        ):
            # we do NOT expect a warning about the OSError in inner_func!
            self.checker.visit_raise(raise_node)
"""
        func_node, node = astroid.extract_node(
            """
        class Foo(object):
            def foo(self): #@
                '''int: docstring ...

                Raises:
                    RuntimeError: Always
                '''
                raise RuntimeError()
                return 10 #@
        """
        )
        with self.assertAddsMessages(
            Message(msg_id="missing-return-doc", node=func_node),
            Message(msg_id="missing-return-type-doc", node=func_node),
        ):
            self.checker.visit_return(node)
def test_missing_field_on_repeated_warns(self):
        node = astroid.extract_node("""
        import repeated_pb2

        outer = repeated_pb2.Outer()
        inner = outer.items.add()
        inner.invalid_field = 123  #@
        """)
        message = pylint.testutils.Message(
            'protobuf-undefined-attribute',
            node=node.targets[0], args=('invalid_field', 'Inner')
        )
        with self.assertAddsMessages(message):
            self.walk(node.root())
def test_nomember_on_c_extension_error_msg(self):
        node = astroid.extract_node(
            """
        from coverage import tracer
        tracer.CTracer  #@
        """
        )
        message = Message(
            "no-member", node=node, args=("Module", "coverage.tracer", "CTracer", "")
        )
        with self.assertAddsMessages(message):
            self.checker.visit_attribute(node)
documentation in a Sphinx style docstring
        """
        func_node, node = astroid.extract_node(
            """
        class Foo(object):
            def foo(self): #@
                '''docstring ...

                :type: int
                '''
                return 10 #@
        """
        )
        with self.assertAddsMessages(
            Message(msg_id="missing-return-doc", node=func_node),
            Message(msg_id="missing-return-type-doc", node=func_node),
        ):
            self.checker.visit_return(node)
class ClassFoo(object):
            def __init__(self, x, y):
                '''docstring foo constructor

                :param y: bla

                missing constructor parameter documentation
                '''

                pass

        """
        )
        constructor_node = node.body[0]
        with self.assertAddsMessages(
            Message(msg_id="missing-param-doc", node=constructor_node, args=("x",)),
            Message(msg_id="missing-type-doc", node=constructor_node, args=("x, y",)),
        ):
            self._visit_methods_of_class(node)
def test_nonstandard_logging_module(self):
        stmts = test_utils.extract_node("""
        from my import logging as blogging #@
        blogging.warn('%s' % '%s')  #@
        """)
        self.checker.visit_module(None)
        self.checker.visit_import(stmts[0])
        with self.assertAddsMessages(Message('logging-not-lazy', node=stmts[1])):
            self.checker.visit_callfunc(stmts[1])

Is your System Free of Underlying Vulnerabilities?
Find Out Now