Example #1
0
 def visit_functiondef(self, node: nodes.FunctionDef) -> None:
     self._check_nonlocal_and_global(node)
     self._check_name_used_prior_global(node)
     if not redefined_by_decorator(
             node) and not utils.is_registered_in_singledispatch_function(
                 node):
         self._check_redefinition(
             node.is_method() and "method" or "function", node)
     # checks for max returns, branch, return in __init__
     returns = node.nodes_of_class(nodes.Return,
                                   skip_klass=(nodes.FunctionDef,
                                               nodes.ClassDef))
     if node.is_method() and node.name == "__init__":
         if node.is_generator():
             self.add_message("init-is-generator", node=node)
         else:
             values = [r.value for r in returns]
             # Are we returning anything but None from constructors
             if any(v for v in values if not utils.is_none(v)):
                 self.add_message("return-in-init", node=node)
     # Check for duplicate names by clustering args with same name for detailed report
     arg_clusters = {}
     arguments: Iterator[Any] = filter(
         None, [node.args.args, node.args.kwonlyargs])
     for arg in itertools.chain.from_iterable(arguments):
         if arg.name in arg_clusters:
             self.add_message(
                 "duplicate-argument-name",
                 node=arg,
                 args=(arg.name, ),
                 confidence=HIGH,
             )
         else:
             arg_clusters[arg.name] = arg
Example #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)
Example #3
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)