Ejemplo n.º 1
0
    def _check_useless_overwritten_methods(
        self,
        node: types.AnyFunctionDef,
        class_name: str,
    ) -> None:
        if node.decorator_list:
            # any decorator can change logic
            # and make this overwrite useful
            return

        call_stmt = self._get_call_stmt_of_useless_method(node)
        if call_stmt is None or not isinstance(call_stmt.func, ast.Attribute):
            return

        attribute = call_stmt.func
        defined_method_name = node.name
        if defined_method_name != attribute.attr:
            return

        if not super_args.is_ordinary_super_call(attribute.value, class_name):
            return

        if not function_args.is_call_matched_by_arguments(node, call_stmt):
            return

        self.add_violation(
            oop.UselessOverwrittenMethodViolation(
                node,
                text=defined_method_name,
            ), )
Ejemplo n.º 2
0
    def _check_useless_lambda(self, node: ast.Lambda) -> None:
        if not isinstance(node.body, ast.Call):
            return
        if not isinstance(node.body.func, ast.Name):
            # We do not track method (attr) calls, since it might me complex.
            return

        if node.args.defaults or list(filter(None, node.args.kw_defaults)):
            # It means that `lambda` has defaults in args,
            # we cannot be sure that these defaults are the same
            # as in the call def, ignoring it.
            # `kw_defaults` can have [None, ...] items.
            return

        if not function_args.is_call_matched_by_arguments(node, node.body):
            return

        self.add_violation(UselessLambdaViolation(node))