How to use the pylint.checkers.utils function in pylint

To help you get started, we’ve selected a few pylint 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 tribe29 / checkmk / tests / testlib / pylint_checker_cmk_module_layers.py View on Github external
    @utils.check_messages('cmk-module-layer-violation')
    def visit_importfrom(self, node: ImportFrom) -> None:
        self._check_import(node, ModuleName(node.modname))
github lad1337 / XDM / rootLibs / pylint / checkers / strings.py View on Github external
def visit_callfunc(self, node):
        func = utils.safe_infer(node.func)
        if (isinstance(func, astng.BoundMethod)
            and isinstance(func.bound, astng.Instance)
            and func.bound.name in ('str', 'unicode', 'bytes')
            and func.name in ('strip', 'lstrip', 'rstrip')
            and node.args):
            arg = utils.safe_infer(node.args[0])
            if not isinstance(arg, astng.Const):
                return
            if len(arg.value) != len(set(arg.value)):
                self.add_message('E1310', node=node,
                                 args=(func.bound.name, func.name))
github PyCQA / pylint / pylint / extensions / overlapping_exceptions.py View on Github external
"""check for empty except"""
        for handler in node.handlers:
            if handler.type is None:
                continue
            if isinstance(handler.type, astroid.BoolOp):
                continue
            try:
                excs = list(_annotated_unpack_infer(handler.type))
            except astroid.InferenceError:
                continue

            handled_in_clause = []
            for part, exc in excs:
                if exc is astroid.Uninferable:
                    continue
                if isinstance(exc, astroid.Instance) and utils.inherit_from_std_ex(exc):
                    # pylint: disable=protected-access
                    exc = exc._proxied

                if not isinstance(exc, astroid.ClassDef):
                    continue

                exc_ancestors = [
                    anc for anc in exc.ancestors() if isinstance(anc, astroid.ClassDef)
                ]

                for prev_part, prev_exc in handled_in_clause:
                    prev_exc_ancestors = [
                        anc
                        for anc in prev_exc.ancestors()
                        if isinstance(anc, astroid.ClassDef)
                    ]
github OCA / pylint-odoo / pylint_odoo / checkers / no_modules.py View on Github external
    @utils.check_messages("print-used")
    def visit_print(self, node):
        self.add_message("print-used", node=node)
github oppia / oppia / scripts / pylint_extensions.py View on Github external
that the return value and the return type are documented.

        Args:
            node: astroid.scoped_nodes.Function. Node for a function or
                method definition in the AST.
        """
        if not docstrings_checker.returns_something(node):
            return

        func_node = node.frame()

        doc = docstrings_checker.docstringify(func_node.doc)
        if not doc.is_valid() and self.config.accept_no_return_doc:
            return

        is_property = checker_utils.decorated_with_property(func_node)

        if not (doc.has_returns() or
                (doc.has_property_returns() and is_property)):
            self.add_message(
                'missing-return-doc',
                node=func_node
            )

        if not (doc.has_rtype() or
                (doc.has_property_type() and is_property)):
            self.add_message(
                'missing-return-type-doc',
                node=func_node
            )
github pylava / pylava_pylint / pylama_pylint / pylint / checkers / stdlib.py View on Github external
def _check_open_mode(self, node):
        """Check that the mode argument of an open or file call is valid."""
        try:
            mode_arg = utils.get_argument_from_call(node, position=1, keyword='mode')
            if mode_arg:
                mode_arg = utils.safe_infer(mode_arg)
                if (isinstance(mode_arg, astroid.Const)
                        and not _VALID_OPEN_MODE_REGEX.match(mode_arg.value)):
                    self.add_message('bad-open-mode', node=node,
                                     args=(mode_arg.value))
        except (utils.NoSuchArgumentError, TypeError):
            pass
github nelfin / pylint-protobuf / pylint_protobuf / __init__.py View on Github external
    @utils.check_messages('protobuf-undefined-attribute')
    def visit_annassign(self, node):
        self._visit_assign(node)
github PyCQA / pylint / pylint / checkers / strings.py View on Github external
# to 0. It will not be present in `named`, so use the value
                # 0 for it.
                key = 0
            if isinstance(key, numbers.Number):
                try:
                    argname = utils.get_argument_from_call(node, key)
                except utils.NoSuchArgumentError:
                    continue
            else:
                if key not in named:
                    continue
                argname = named[key]
            if argname in (astroid.Uninferable, None):
                continue
            try:
                argument = utils.safe_infer(argname)
            except astroid.InferenceError:
                continue
            if not specifiers or not argument:
                # No need to check this key if it doesn't
                # use attribute / item access
                continue
            if argument.parent and isinstance(argument.parent, astroid.Arguments):
                # Ignore any object coming from an argument,
                # because we can't infer its value properly.
                continue
            previous = argument
            parsed = []
            for is_attribute, specifier in specifiers:
                if previous is astroid.Uninferable:
                    break
                parsed.append((is_attribute, specifier))
github PyCQA / pylint / pylint / checkers / stdlib.py View on Github external
def _check_open_mode(self, node):
        """Check that the mode argument of an open or file call is valid."""
        try:
            mode_arg = utils.get_argument_from_call(node, position=1, keyword="mode")
        except utils.NoSuchArgumentError:
            return
        if mode_arg:
            mode_arg = utils.safe_infer(mode_arg)
            if isinstance(mode_arg, astroid.Const) and not _check_mode_str(
                mode_arg.value
            ):
                self.add_message("bad-open-mode", node=node, args=mode_arg.value)
github marslo / myvim / Configurations / Offline_Packages / bundle / python-mode / submodules / pylint / pylint / extensions / _check_docs_utils.py View on Github external
def get_setters_property(node):
    """Get the property node for the given setter node.

    :param node: The node to get the property for.
    :type node: astroid.FunctionDef

    :rtype: astroid.FunctionDef or None
    :returns: The node relating to the property of the given setter node,
        or None if one could not be found.
    """
    property_ = None

    property_name = get_setters_property_name(node)
    class_node = utils.node_frame_class(node)
    if property_name and class_node:
        class_attrs = class_node.getattr(node.name)
        for attr in class_attrs:
            if utils.decorated_with_property(attr):
                property_ = attr
                break

    return property_