Ejemplo n.º 1
0
 def _check_wrong_body_nodes(self, node: ast.ClassDef) -> None:
     for sub_node in node.body:
         if isinstance(sub_node, self._allowed_body_nodes):
             continue
         if strings.is_doc_string(sub_node):
             continue
         self.add_violation(oop.WrongClassBodyContentViolation(sub_node))
Ejemplo n.º 2
0
    def _check_expression(
        self,
        node: ast.Expr,
        is_first: bool = False,
    ) -> None:
        if isinstance(node.value, self._have_effect):
            return

        if is_first and strings.is_doc_string(node):
            if isinstance(nodes.get_parent(node), self._have_doc_strings):
                return

        self.add_violation(StatementHasNoEffectViolation(node))
Ejemplo n.º 3
0
    def _check_init_contents(self, node: ast.Module) -> None:
        if not self._is_init() or not node.body:
            return

        if not self.options.i_control_code:
            return

        if len(node.body) > 1:
            self.add_violation(InitModuleHasLogicViolation())
            return

        if not is_doc_string(node.body[0]):
            self.add_violation(InitModuleHasLogicViolation())
Ejemplo n.º 4
0
    def _get_call_stmt_of_useless_method(
        self,
        node: types.AnyFunctionDef,
    ) -> Optional[ast.Call]:
        # consider next body as possible candidate of useless method:
        # 1) Optional[docstring]
        # 2) return statement with call
        statements_number = len(node.body)
        if statements_number > 2 or statements_number == 0:
            return None

        if statements_number == 2:
            if not strings.is_doc_string(node.body[0]):
                return None

        return_stmt = node.body[-1]
        if not isinstance(return_stmt, ast.Return):
            return None

        call_stmt = return_stmt.value
        if not isinstance(call_stmt, ast.Call):
            return None
        return call_stmt