summaryrefslogtreecommitdiff
path: root/pylint/checkers
diff options
context:
space:
mode:
authorDaniƫl van Noord <13665637+DanielNoord@users.noreply.github.com>2021-11-14 17:09:35 +0200
committerGitHub <noreply@github.com>2021-11-14 16:09:35 +0100
commit48d584babd0df99bd469aba0e4aeed3d8f97fff9 (patch)
treeba5e117a0e8551f3bcda8e3043963e75da043b6f /pylint/checkers
parente5082d3f9401dbcf65b40ce6a819d2a09beccb5c (diff)
downloadpylint-git-48d584babd0df99bd469aba0e4aeed3d8f97fff9.tar.gz
Move ``misplaced-comparison-constant`` to optional extension (#5298)
* Move ``misplaced-comparison-constant`` to optional extension * Update functional tests to increase coverage Co-authored-by: Pierre Sassoulas <pierre.sassoulas@gmail.com>
Diffstat (limited to 'pylint/checkers')
-rw-r--r--pylint/checkers/base.py19
1 files changed, 1 insertions, 18 deletions
diff --git a/pylint/checkers/base.py b/pylint/checkers/base.py
index 510b2cdcf..fd18fb867 100644
--- a/pylint/checkers/base.py
+++ b/pylint/checkers/base.py
@@ -214,7 +214,7 @@ DEFAULT_ARGUMENT_SYMBOLS = dict(
)
},
)
-REVERSED_COMPS = {"<": ">", "<=": ">=", ">": "<", ">=": "<="}
+
COMPARISON_OPERATORS = frozenset(("==", "!=", "<", ">", "<=", ">="))
# List of methods which can be redefined
REDEFINABLE_METHODS = frozenset(("__module__",))
@@ -2323,13 +2323,6 @@ class ComparisonChecker(_BasicChecker):
"Used when an expression is compared to singleton "
"values like True, False or None.",
),
- "C0122": (
- "Comparison should be %s",
- "misplaced-comparison-constant",
- "Used when the constant is placed on the left side "
- "of a comparison. It is usually clearer in intent to "
- "place it in the right hand side of the comparison.",
- ),
"C0123": (
"Use isinstance() rather than type() for a typecheck.",
"unidiomatic-typecheck",
@@ -2478,13 +2471,6 @@ class ComparisonChecker(_BasicChecker):
if is_const or is_other_literal:
self.add_message("literal-comparison", node=node)
- def _check_misplaced_constant(self, node, left, right, operator):
- if isinstance(right, nodes.Const):
- return
- operator = REVERSED_COMPS.get(operator, operator)
- suggestion = f"{right.as_string()} {operator} {left.value!r}"
- self.add_message("misplaced-comparison-constant", node=node, args=(suggestion,))
-
def _check_logical_tautology(self, node: nodes.Compare):
"""Check if identifier is compared against itself.
:param node: Compare node
@@ -2532,7 +2518,6 @@ class ComparisonChecker(_BasicChecker):
@utils.check_messages(
"singleton-comparison",
- "misplaced-comparison-constant",
"unidiomatic-typecheck",
"literal-comparison",
"comparison-with-itself",
@@ -2549,8 +2534,6 @@ class ComparisonChecker(_BasicChecker):
left = node.left
operator, right = node.ops[0]
- if operator in COMPARISON_OPERATORS and isinstance(left, nodes.Const):
- self._check_misplaced_constant(node, left, right, operator)
if operator in ("==", "!="):
self._check_singleton_comparison(