def visit_return(self, node): """Visits a function node that contains a return statement and verifies 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() if not isinstance(func_node, astroid.FunctionDef): return 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)
def check_functiondef_returns(self, node, node_doc): if not node_doc.supports_yields and node.is_generator(): return return_nodes = node.nodes_of_class(astroid.Return) if ((node_doc.has_returns() or node_doc.has_rtype()) and not any( docstrings_checker.returns_something(ret_node) for ret_node in return_nodes)): self.add_message('redundant-returns-doc', node=node)
def check_functiondef_returns(self, node, node_doc): """Checks whether a function documented with a return value actually has a return statement in its definition. Args: node: astroid.scoped_nodes.Function. Node for a function or method definition in the AST. node_doc: Docstring. Pylint Docstring class instance representing a node's docstring. """ if not node_doc.supports_yields and node.is_generator(): return return_nodes = node.nodes_of_class(astroid.Return) if ((node_doc.has_returns() or node_doc.has_rtype()) and not any( docstrings_checker.returns_something(ret_node) for ret_node in return_nodes)): self.add_message('redundant-returns-doc', node=node)
def visit_return(self, node): if not docstrings_checker.returns_something(node): return func_node = node.frame() if not isinstance(func_node, astroid.FunctionDef): return 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)