def _ensure_super_context(self, node: ast.Call) -> None:
     parent_context = getattr(node, 'wps_context', None)
     if isinstance(parent_context, (ast.FunctionDef, ast.AsyncFunctionDef)):
         grand_context = getattr(parent_context, 'wps_context', None)
         grand_context = nodes.get_context(parent_context)
         if isinstance(grand_context, ast.ClassDef):
             return
     self.add_violation(
         IncorrectSuperCallViolation(node, text='not inside method'), )
예제 #2
0
    def _check_mutable_constant(self, node: ast.Assign) -> None:
        context = get_context(node)
        if not isinstance(context, ast.Module):
            return
        for target in node.targets:
            if not isinstance(target, ast.Name) or not is_constant(target.id):
                continue

            if isinstance(node.value, self._mutable_nodes):
                self.add_violation(MutableModuleConstantViolation(target))
예제 #3
0
    def _check_bound_methods(self, node: types.AnyFunctionDef) -> None:
        node_context = get_context(node)
        if not isinstance(node_context, ast.ClassDef):
            return

        if len(get_all_arguments(node)) == 0:
            self.add_violation(
                MethodWithoutArgumentsViolation(node, text=node.name), )

        if node.name in constants.MAGIC_METHODS_BLACKLIST:
            self.add_violation(BadMagicMethodViolation(node, text=node.name))
예제 #4
0
    def _check_slots(self, node: ast.Assign) -> None:
        context = get_context(node)
        if not isinstance(context, ast.ClassDef):
            return

        if not self._contains_slots_assign(node):
            return

        if isinstance(node.value, self._blacklisted_slots_nodes):
            self.add_violation(IncorrectSlotsViolation(node))
            return

        if isinstance(node.value, ast.Tuple):
            self._count_slots_items(node, node.value)