Esempio n. 1
0
 def _check_simplifiable_if(self, node: ast.If) -> None:
     chain = getattr(node, 'wps_chain', None)
     chained = getattr(node, 'wps_chained', None)
     if chain is None and chained is None:
         body_var = self._is_simplifiable_assign(node.body)
         else_var = self._is_simplifiable_assign(node.orelse)
         if body_var and body_var == else_var:
             self.add_violation(SimplifiableIfViolation(node))
Esempio n. 2
0
    def _check_simplifiable_ifexpr(self, node: ast.IfExp) -> None:
        conditions = set()
        if isinstance(node.body, ast.NameConstant):
            conditions.add(node.body.value)
        if isinstance(node.orelse, ast.NameConstant):
            conditions.add(node.orelse.value)

        if conditions == {True, False}:
            self.add_violation(SimplifiableIfViolation(node))
Esempio n. 3
0
 def _check_simplifiable_if(self, node: ast.If) -> None:
     if not ifs.is_elif(node) and not ifs.root_if(node):
         body_var = self._is_simplifiable_assign(node.body)
         else_var = self._is_simplifiable_assign(node.orelse)
         if body_var and body_var == else_var:
             self.add_violation(SimplifiableIfViolation(node))