| Index: flake8-eyeo/flake8_eyeo.py |
| =================================================================== |
| --- a/flake8-eyeo/flake8_eyeo.py |
| +++ b/flake8-eyeo/flake8_eyeo.py |
| @@ -287,6 +287,36 @@ |
| self.generic_visit(node) |
| + def visit_BoolOp(self, node): |
| + if isinstance(node.op, ast.Or): |
| + left = node.values[0] |
| + right = node.values[1] |
|
Sebastian Noack
2017/12/10 23:19:57
What if there is another condition in between? E.g
|
| + if (isinstance(left, ast.Compare) and |
| + isinstance(right, ast.Compare)): |
| + if (isinstance(left.ops[0], ast.Eq) and |
| + isinstance(left.ops[0], ast.Eq) or |
|
Sebastian Noack
2017/12/10 23:19:57
This expression is the same as the left-hand side
|
| + (isinstance(left.ops[0], ast.NotEq) and |
| + isinstance(left.ops[0], ast.NotEq))): |
| + value1names = [] |
| + value2names = [] |
| + # Gather variable names from the left comparison |
| + if isinstance(left.left, ast.Name): |
|
Sebastian Noack
2017/12/10 23:19:57
What if it is an Attribute node? E.g: x.a == 1 or
|
| + value1names.append(left.left.id) |
| + if isinstance(left.comparators[0], ast.Name): |
| + value1names.append(left.comparators[0].id) |
| + # Gather variable names from the right comparison |
| + if isinstance(right.left, ast.Name): |
| + value2names.append(right.left.id) |
| + if isinstance(right.comparators[0], ast.Name): |
| + value2names.append(right.comparators[0].id) |
| + # Check for duplicates |
| + for i in value1names: |
| + if i in value2names: |
| + self.errors.append((node, 'A208 `{} == x or {} == ' |
| + 'y` should be `{} in {{x' |
| + ', y}}`'.format(i, i, |
| + i))) |
| + |
| def _check_deprecated(self, node, name): |
| substitute = DISCOURAGED_APIS.get(name) |
| if substitute: |
| @@ -391,7 +421,7 @@ |
| checker_state['has_unicode_literals'] = True |
| for kind, token, start, end, _ in tokens: |
| - if kind == tokenize.INDENT or kind == tokenize.DEDENT: |
| + if kind in {tokenize.INDENT, tokenize.DEDENT}: |
| continue |
| if kind == tokenize.STRING: |