diff options
author | Claudiu Popa <pcmanticore@gmail.com> | 2015-10-26 16:06:03 +0000 |
---|---|---|
committer | Claudiu Popa <pcmanticore@gmail.com> | 2015-10-26 16:06:03 +0000 |
commit | 5dcbd07be9af4b20efcef9577e47528688a0b1d4 (patch) | |
tree | dd6f64cdfdea08a626d2559ed20ef3b3da873fe2 | |
parent | 23ce091db69414000823511ed8cd3e6c298e3550 (diff) | |
download | pylint-5dcbd07be9af4b20efcef9577e47528688a0b1d4.tar.gz |
Simplify _check_misplaced_constant.
-rw-r--r-- | pylint/checkers/base.py | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/pylint/checkers/base.py b/pylint/checkers/base.py index a526dda..fd3f285 100644 --- a/pylint/checkers/base.py +++ b/pylint/checkers/base.py @@ -85,6 +85,7 @@ DEFAULT_ARGUMENT_SYMBOLS = dict( zip(['.'.join([astroid.bases.BUILTINS, x]) for x in ('set', 'dict', 'list')], ['set()', '{}', '[]']) ) +REVERSED_COMPS = {'<': '>', '<=': '>=', '>': '<', '>=': '<='} del re @@ -1490,14 +1491,12 @@ class ComparisonChecker(_BasicChecker): args=(None, "'expr is None'")) def _check_misplaced_constant(self, node, left, right, operator): - if not isinstance(right, astroid.Const): - reverse_op = {'<': '>', '<=': '>=', '>': '<', '>=': '<='} - if operator in reverse_op: - operator = reverse_op[operator] - - suggestion = '%s %s %s' % (right.as_string(), operator, left.value) - self.add_message('misplaced-comparison-constant', node=node, - args=(suggestion,)) + if isinstance(right, astroid.Const): + return + operator = REVERSED_COMPS.get(operator, operator) + suggestion = '%s %s %s' % (right.as_string(), operator, left.value) + self.add_message('misplaced-comparison-constant', node=node, + args=(suggestion,)) @check_messages('singleton-comparison', 'misplaced-comparison-constant') def visit_compare(self, node): |