Exemplo n.º 1
0
    def leave_functiondef(self, node: nodes.FunctionDef) -> None:
        """On method node, check if this method couldn't be a function.

        ignore class, static and abstract methods, initializer,
        methods overridden from a parent class.
        """
        if node.is_method():
            first = self._first_attrs.pop()
            if first is None:
                return
            class_node = node.parent.frame(future=True)
            if (
                self._meth_could_be_func
                and node.type == "method"
                and node.name not in PYMETHODS
                and not (
                    node.is_abstract()
                    or overrides_a_method(class_node, node.name)
                    or decorated_with_property(node)
                    or _has_bare_super_call(node)
                    or is_protocol_class(class_node)
                    or is_overload_stub(node)
                )
            ):
                self.add_message("no-self-use", node=node, confidence=INFERENCE)
Exemplo n.º 2
0
    def check_functiondef_yields(self, node: nodes.FunctionDef,
                                 node_doc: Docstring) -> None:
        if not node_doc.supports_yields or node.is_abstract():
            return

        if (node_doc.has_yields()
                or node_doc.has_yields_type()) and not node.is_generator():
            self.add_message("redundant-yields-doc", node=node)
Exemplo n.º 3
0
Arquivo: app.py Projeto: 45deg/pypuml
 def visit_functiondef(self, ast: ast_node.FunctionDef):
     args = ast.argnames()
     ret_type = " -> %s" % ast.returns.as_string() if ast.returns else ""
     modifier = ""
     if ast.is_abstract():
         modifier += "{abstract} "
     if ast.type in {"classmethod", "staticmethod"}:
         modifier += "{static} "
     self.write("%s%s(%s)%s" % (modifier, ast.name, ','.join(args), ret_type))
Exemplo n.º 4
0
    def check_functiondef_returns(self, node: nodes.FunctionDef,
                                  node_doc: Docstring) -> None:
        if (not node_doc.supports_yields
                and node.is_generator()) or node.is_abstract():
            return

        return_nodes = node.nodes_of_class(astroid.Return)
        if (node_doc.has_returns() or node_doc.has_rtype()) and not any(
                utils.returns_something(ret_node)
                for ret_node in return_nodes):
            self.add_message("redundant-returns-doc", node=node)
Exemplo n.º 5
0
    def _add_raise_message(self, missing_excs: set[str],
                           node: nodes.FunctionDef) -> None:
        """Adds a message on :param:`node` for the missing exception type.

        :param missing_excs: A list of missing exception types.

        :param node: The node show the message on.
        """
        if node.is_abstract():
            try:
                missing_excs.remove("NotImplementedError")
            except KeyError:
                pass

        if not missing_excs:
            return

        self.add_message("missing-raises-doc",
                         args=(", ".join(sorted(missing_excs)), ),
                         node=node)