Пример #1
0
    def _count_slots_items(
        self,
        node: ast.Assign,
        elements: ast.Tuple,
    ) -> None:
        fields: List[str] = []
        for tuple_item in elements.elts:
            if not isinstance(tuple_item, ast.Str):
                self.add_violation(IncorrectSlotsViolation(node))
                return
            fields.append(tuple_item.s)

        for _, counter in Counter(fields).items():
            if counter > 1:
                self.add_violation(IncorrectSlotsViolation(node))
                return
Пример #2
0
    def _check_slots(self, node: ast.Assign) -> None:
        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)