def _check_multi_statement_line(self, node, line): """Check for lines containing multiple statements.""" # Do not warn about multiple nested context managers # in with statements. if isinstance(node, nodes.With): return # For try... except... finally..., the two nodes # appear to be on the same line due to how the AST is built. if isinstance(node, nodes.TryExcept) and isinstance( node.parent, nodes.TryFinally): return if (isinstance(node.parent, nodes.If) and not node.parent.orelse and self.config.single_line_if_stmt): return if (isinstance(node.parent, nodes.ClassDef) and len(node.parent.body) == 1 and self.config.single_line_class_stmt): return # Function overloads that use ``Ellipsis`` are exempted. if isinstance(node, nodes.Expr) and (isinstance(node.value, nodes.Ellipsis) or (isinstance(node.value, nodes.Const) and node.value.value is Ellipsis)): frame = node.frame() if is_overload_stub(frame) or is_protocol_class( node_frame_class(frame)): return self.add_message("multiple-statements", node=node) self._visited_lines[line] = 2
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)