def _check_unique_assignment(
     self,
     node: AnyAssign,
     names: List[str],
 ) -> None:
     for used_name, count in Counter(names).items():
         if count > 1:
             self.add_violation(
                 best_practices.ReassigningVariableToItselfViolation(
                     node,
                     text=used_name,
                 ), )
    def _check_reassignment(
        self,
        node: AnyAssign,
        names: List[str],
    ) -> None:
        if not node.value:
            return

        var_values = name_nodes.get_variables_from_node(node.value)
        for var_name, var_value in itertools.zip_longest(names, var_values):
            if var_name == var_value:
                self.add_violation(
                    best_practices.ReassigningVariableToItselfViolation(
                        node,
                        text=var_name,
                    ), )
Beispiel #3
0
 def _check_unique_assignment(
     self,
     node: AnyAssign,
     names: List[str],
 ) -> None:
     used_names = filter(
         lambda assigned_name: not access.is_unused(assigned_name),
         names,
     )
     for used_name, count in Counter(used_names).items():
         if count > 1:
             self.add_violation(
                 best_practices.ReassigningVariableToItselfViolation(
                     node,
                     text=used_name,
                 ), )
Beispiel #4
0
    def _check_reassignment(
        self,
        node: AnyAssign,
        names: List[str],
    ) -> None:
        if not node.value:
            return

        if isinstance(nodes.get_context(node), ast.ClassDef):
            return  # This is not a variable, but a class property

        var_values = name_nodes.get_variables_from_node(node.value)
        for var_name, var_value in itertools.zip_longest(names, var_values):
            if var_name == var_value:
                self.add_violation(
                    best_practices.ReassigningVariableToItselfViolation(
                        node,
                        text=var_name,
                    ), )
Beispiel #5
0
    def _check_reassignment(
        self,
        node: AnyAssign,
        names: List[str],
    ) -> None:
        if not node.value:
            return

        if self._is_reassignment_edge_case(node):
            return

        var_values = name_nodes.get_variables_from_node(node.value)
        if len(names) <= 1 < len(var_values):
            # It means that we have something like `x = (y, z)`
            # or even `x = (x, y)`, which is also fine. See #1807
            return

        for var_name, var_value in itertools.zip_longest(names, var_values):
            if var_name == var_value:
                self.add_violation(
                    best_practices.ReassigningVariableToItselfViolation(
                        node,
                        text=var_name,
                    ), )