We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Forbid to compare the identical variables
# Rule request

<!-- Thanks for coming up with a proposal! -->

## Thesis

We need to find cases like this: `if some_value == some_value:`.
We also need to find other operators: `is`, `is not`, `>`, `<`, `!=`, `>=`, `<=`.

## Reasoning

It clearly does not make any sense. It is a bug in the source code.

Related: https://help.semmle.com/wiki/display/PYTHON/Comparison+of+identical+values


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `wemake_python_styleguide/visitors/ast/comparisons.py`
Content:
```
1 # -*- coding: utf-8 -*-
2 
3 import ast
4 from typing import ClassVar, Sequence
5 
6 from wemake_python_styleguide.types import AnyNodes
7 from wemake_python_styleguide.violations.consistency import (
8     ComparisonOrderViolation,
9     ConstantComparisonViolation,
10     MultipleInComparisonViolation,
11 )
12 from wemake_python_styleguide.visitors.base import BaseNodeVisitor
13 
14 
15 class ConstantComparisonVisitor(BaseNodeVisitor):
16     """Restricts the comparison of literals."""
17 
18     def _check_is_literal(self, node: ast.AST) -> bool:
19         """
20         Checks for nodes that contains only constants.
21 
22         If the node contains only literals it will be evaluted.
23         When node relies on some other names, it won't be evaluted.
24         """
25         try:
26             ast.literal_eval(node)
27         except ValueError:
28             return False
29         else:
30             return True
31 
32     def _check_literal_compare(self, node: ast.Compare) -> None:
33         last_was_literal = self._check_is_literal(node.left)
34         for comparator in node.comparators:
35             next_is_literal = self._check_is_literal(comparator)
36             if last_was_literal and next_is_literal:
37                 self.add_violation(ConstantComparisonViolation(node))
38                 break
39             last_was_literal = next_is_literal
40 
41     def visit_Compare(self, node: ast.Compare) -> None:
42         """
43         Ensures that compares are written correctly.
44 
45         Raises:
46             ConstantComparisonViolation
47 
48         """
49         self._check_literal_compare(node)
50         self.generic_visit(node)
51 
52 
53 class WrongOrderVisitor(BaseNodeVisitor):
54     """Restricts comparision where argument doesn't come first."""
55 
56     _allowed_left_nodes: ClassVar[AnyNodes] = (
57         ast.Name,
58         ast.Call,
59         ast.Attribute,
60     )
61 
62     _special_cases: ClassVar[AnyNodes] = (
63         ast.In,
64         ast.NotIn,
65     )
66 
67     def _is_special_case(self, node: ast.Compare) -> bool:
68         """
69         Operators ``in`` and ``not in`` are special cases.
70 
71         Why? Because it is perfectly fine to use something like:
72         ``if 'key' in some_dict: ...``
73         This should not be an issue.
74 
75         When there are multiple special operators it is still a separate issue.
76         """
77         return isinstance(node.ops[0], self._special_cases)
78 
79     def _is_left_node_valid(self, left: ast.AST) -> bool:
80         if isinstance(left, self._allowed_left_nodes):
81             return True
82         if isinstance(left, ast.BinOp):
83             return (
84                 self._is_left_node_valid(left.left) or
85                 self._is_left_node_valid(left.right)
86             )
87         return False
88 
89     def _has_wrong_nodes_on_the_right(
90         self,
91         comparators: Sequence[ast.AST],
92     ) -> bool:
93         for right in comparators:
94             if isinstance(right, self._allowed_left_nodes):
95                 return True
96             if isinstance(right, ast.BinOp):
97                 return self._has_wrong_nodes_on_the_right([
98                     right.left, right.right,
99                 ])
100         return False
101 
102     def _check_ordering(self, node: ast.Compare) -> None:
103         if self._is_left_node_valid(node.left):
104             return
105 
106         if self._is_special_case(node):
107             return
108 
109         if len(node.comparators) > 1:
110             return
111 
112         if not self._has_wrong_nodes_on_the_right(node.comparators):
113             return
114 
115         self.add_violation(ComparisonOrderViolation(node))
116 
117     def visit_Compare(self, node: ast.Compare) -> None:
118         """
119         Forbids comparision where argument doesn't come first.
120 
121         Raises:
122             ComparisonOrderViolation
123 
124         """
125         self._check_ordering(node)
126         self.generic_visit(node)
127 
128 
129 # TODO(@sobolevn): refactor to be a single visitor
130 class MultipleInVisitor(BaseNodeVisitor):
131     """Restricts comparision where multiple `in`s are used."""
132 
133     def _has_multiple_in_comparisons(self, node: ast.Compare) -> bool:
134         count = 0
135         for op in node.ops:
136             if isinstance(op, ast.In):
137                 count += 1
138         return count > 1
139 
140     def _count_in_comparisons(self, node: ast.Compare) -> None:
141         if self._has_multiple_in_comparisons(node):
142             self.add_violation(MultipleInComparisonViolation(node))
143 
144     def visit_Compare(self, node: ast.Compare) -> None:
145         """
146         Forbids comparisons including multiple 'in's in a statement.
147 
148         Raise:
149             MultipleInComparisonViolation
150 
151         """
152         self._count_in_comparisons(node)
153         self.generic_visit(node)
154
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/wemake_python_styleguide/visitors/ast/comparisons.py b/wemake_python_styleguide/visitors/ast/comparisons.py
--- a/wemake_python_styleguide/visitors/ast/comparisons.py
+++ b/wemake_python_styleguide/visitors/ast/comparisons.py
@@ -151,3 +151,32 @@
         """
         self._count_in_comparisons(node)
         self.generic_visit(node)
+
+
+class RedundantComparisonVisitor(BaseNodeVisitor):
+    """Restricts the comparison where always same result."""
+
+    def visit_Compare(self, node: ast.Compare) -> None:
+        """
+        Ensures that compares are not for same variable.
+
+        Raises:
+            ConstantComparisonViolation
+
+        """
+        self._check_redundant_compare(node)
+        self.generic_visit(node)
+
+    def _is_same_variable(self, left: ast.AST, right: ast.AST) -> bool:
+        if isinstance(left, ast.Name) and isinstance(right, ast.Name):
+            if left.id is right.id:
+                return True
+        return False
+
+    def _check_redundant_compare(self, node: ast.Compare) -> None:
+        last_variable = node.left
+        for next_variable in node.comparators:
+            if self._is_same_variable(last_variable, next_variable):
+                self.add_violation(ConstantComparisonViolation(node))
+                break
+            last_variable = next_variable

{"golden_diff": "diff --git a/wemake_python_styleguide/visitors/ast/comparisons.py b/wemake_python_styleguide/visitors/ast/comparisons.py\n--- a/wemake_python_styleguide/visitors/ast/comparisons.py\n+++ b/wemake_python_styleguide/visitors/ast/comparisons.py\n@@ -151,3 +151,32 @@\n         \"\"\"\n         self._count_in_comparisons(node)\n         self.generic_visit(node)\n+\n+\n+class RedundantComparisonVisitor(BaseNodeVisitor):\n+    \"\"\"Restricts the comparison where always same result.\"\"\"\n+\n+    def visit_Compare(self, node: ast.Compare) -> None:\n+        \"\"\"\n+        Ensures that compares are not for same variable.\n+\n+        Raises:\n+            ConstantComparisonViolation\n+\n+        \"\"\"\n+        self._check_redundant_compare(node)\n+        self.generic_visit(node)\n+\n+    def _is_same_variable(self, left: ast.AST, right: ast.AST) -> bool:\n+        if isinstance(left, ast.Name) and isinstance(right, ast.Name):\n+            if left.id is right.id:\n+                return True\n+        return False\n+\n+    def _check_redundant_compare(self, node: ast.Compare) -> None:\n+        last_variable = node.left\n+        for next_variable in node.comparators:\n+            if self._is_same_variable(last_variable, next_variable):\n+                self.add_violation(ConstantComparisonViolation(node))\n+                break\n+            last_variable = next_variable\n", "issue": "Forbid to compare the identical variables\n# Rule request\r\n\r\n<!-- Thanks for coming up with a proposal! -->\r\n\r\n## Thesis\r\n\r\nWe need to find cases like this: `if some_value == some_value:`.\r\nWe also need to find other operators: `is`, `is not`, `>`, `<`, `!=`, `>=`, `<=`.\r\n\r\n## Reasoning\r\n\r\nIt clearly does not make any sense. It is a bug in the source code.\r\n\r\nRelated: https://help.semmle.com/wiki/display/PYTHON/Comparison+of+identical+values\r\n\n", "before_files": [{"content": "# -*- coding: utf-8 -*-\n\nimport ast\nfrom typing import ClassVar, Sequence\n\nfrom wemake_python_styleguide.types import AnyNodes\nfrom wemake_python_styleguide.violations.consistency import (\n    ComparisonOrderViolation,\n    ConstantComparisonViolation,\n    MultipleInComparisonViolation,\n)\nfrom wemake_python_styleguide.visitors.base import BaseNodeVisitor\n\n\nclass ConstantComparisonVisitor(BaseNodeVisitor):\n    \"\"\"Restricts the comparison of literals.\"\"\"\n\n    def _check_is_literal(self, node: ast.AST) -> bool:\n        \"\"\"\n        Checks for nodes that contains only constants.\n\n        If the node contains only literals it will be evaluted.\n        When node relies on some other names, it won't be evaluted.\n        \"\"\"\n        try:\n            ast.literal_eval(node)\n        except ValueError:\n            return False\n        else:\n            return True\n\n    def _check_literal_compare(self, node: ast.Compare) -> None:\n        last_was_literal = self._check_is_literal(node.left)\n        for comparator in node.comparators:\n            next_is_literal = self._check_is_literal(comparator)\n            if last_was_literal and next_is_literal:\n                self.add_violation(ConstantComparisonViolation(node))\n                break\n            last_was_literal = next_is_literal\n\n    def visit_Compare(self, node: ast.Compare) -> None:\n        \"\"\"\n        Ensures that compares are written correctly.\n\n        Raises:\n            ConstantComparisonViolation\n\n        \"\"\"\n        self._check_literal_compare(node)\n        self.generic_visit(node)\n\n\nclass WrongOrderVisitor(BaseNodeVisitor):\n    \"\"\"Restricts comparision where argument doesn't come first.\"\"\"\n\n    _allowed_left_nodes: ClassVar[AnyNodes] = (\n        ast.Name,\n        ast.Call,\n        ast.Attribute,\n    )\n\n    _special_cases: ClassVar[AnyNodes] = (\n        ast.In,\n        ast.NotIn,\n    )\n\n    def _is_special_case(self, node: ast.Compare) -> bool:\n        \"\"\"\n        Operators ``in`` and ``not in`` are special cases.\n\n        Why? Because it is perfectly fine to use something like:\n        ``if 'key' in some_dict: ...``\n        This should not be an issue.\n\n        When there are multiple special operators it is still a separate issue.\n        \"\"\"\n        return isinstance(node.ops[0], self._special_cases)\n\n    def _is_left_node_valid(self, left: ast.AST) -> bool:\n        if isinstance(left, self._allowed_left_nodes):\n            return True\n        if isinstance(left, ast.BinOp):\n            return (\n                self._is_left_node_valid(left.left) or\n                self._is_left_node_valid(left.right)\n            )\n        return False\n\n    def _has_wrong_nodes_on_the_right(\n        self,\n        comparators: Sequence[ast.AST],\n    ) -> bool:\n        for right in comparators:\n            if isinstance(right, self._allowed_left_nodes):\n                return True\n            if isinstance(right, ast.BinOp):\n                return self._has_wrong_nodes_on_the_right([\n                    right.left, right.right,\n                ])\n        return False\n\n    def _check_ordering(self, node: ast.Compare) -> None:\n        if self._is_left_node_valid(node.left):\n            return\n\n        if self._is_special_case(node):\n            return\n\n        if len(node.comparators) > 1:\n            return\n\n        if not self._has_wrong_nodes_on_the_right(node.comparators):\n            return\n\n        self.add_violation(ComparisonOrderViolation(node))\n\n    def visit_Compare(self, node: ast.Compare) -> None:\n        \"\"\"\n        Forbids comparision where argument doesn't come first.\n\n        Raises:\n            ComparisonOrderViolation\n\n        \"\"\"\n        self._check_ordering(node)\n        self.generic_visit(node)\n\n\n# TODO(@sobolevn): refactor to be a single visitor\nclass MultipleInVisitor(BaseNodeVisitor):\n    \"\"\"Restricts comparision where multiple `in`s are used.\"\"\"\n\n    def _has_multiple_in_comparisons(self, node: ast.Compare) -> bool:\n        count = 0\n        for op in node.ops:\n            if isinstance(op, ast.In):\n                count += 1\n        return count > 1\n\n    def _count_in_comparisons(self, node: ast.Compare) -> None:\n        if self._has_multiple_in_comparisons(node):\n            self.add_violation(MultipleInComparisonViolation(node))\n\n    def visit_Compare(self, node: ast.Compare) -> None:\n        \"\"\"\n        Forbids comparisons including multiple 'in's in a statement.\n\n        Raise:\n            MultipleInComparisonViolation\n\n        \"\"\"\n        self._count_in_comparisons(node)\n        self.generic_visit(node)\n", "path": "wemake_python_styleguide/visitors/ast/comparisons.py"}], "after_files": [{"content": "# -*- coding: utf-8 -*-\n\nimport ast\nfrom typing import ClassVar, Sequence\n\nfrom wemake_python_styleguide.types import AnyNodes\nfrom wemake_python_styleguide.violations.consistency import (\n    ComparisonOrderViolation,\n    ConstantComparisonViolation,\n    MultipleInComparisonViolation,\n)\nfrom wemake_python_styleguide.visitors.base import BaseNodeVisitor\n\n\nclass ConstantComparisonVisitor(BaseNodeVisitor):\n    \"\"\"Restricts the comparison of literals.\"\"\"\n\n    def _check_is_literal(self, node: ast.AST) -> bool:\n        \"\"\"\n        Checks for nodes that contains only constants.\n\n        If the node contains only literals it will be evaluted.\n        When node relies on some other names, it won't be evaluted.\n        \"\"\"\n        try:\n            ast.literal_eval(node)\n        except ValueError:\n            return False\n        else:\n            return True\n\n    def _check_literal_compare(self, node: ast.Compare) -> None:\n        last_was_literal = self._check_is_literal(node.left)\n        for comparator in node.comparators:\n            next_is_literal = self._check_is_literal(comparator)\n            if last_was_literal and next_is_literal:\n                self.add_violation(ConstantComparisonViolation(node))\n                break\n            last_was_literal = next_is_literal\n\n    def visit_Compare(self, node: ast.Compare) -> None:\n        \"\"\"\n        Ensures that compares are written correctly.\n\n        Raises:\n            ConstantComparisonViolation\n\n        \"\"\"\n        self._check_literal_compare(node)\n        self.generic_visit(node)\n\n\nclass WrongOrderVisitor(BaseNodeVisitor):\n    \"\"\"Restricts comparision where argument doesn't come first.\"\"\"\n\n    _allowed_left_nodes: ClassVar[AnyNodes] = (\n        ast.Name,\n        ast.Call,\n        ast.Attribute,\n    )\n\n    _special_cases: ClassVar[AnyNodes] = (\n        ast.In,\n        ast.NotIn,\n    )\n\n    def _is_special_case(self, node: ast.Compare) -> bool:\n        \"\"\"\n        Operators ``in`` and ``not in`` are special cases.\n\n        Why? Because it is perfectly fine to use something like:\n        ``if 'key' in some_dict: ...``\n        This should not be an issue.\n\n        When there are multiple special operators it is still a separate issue.\n        \"\"\"\n        return isinstance(node.ops[0], self._special_cases)\n\n    def _is_left_node_valid(self, left: ast.AST) -> bool:\n        if isinstance(left, self._allowed_left_nodes):\n            return True\n        if isinstance(left, ast.BinOp):\n            return (\n                self._is_left_node_valid(left.left) or\n                self._is_left_node_valid(left.right)\n            )\n        return False\n\n    def _has_wrong_nodes_on_the_right(\n        self,\n        comparators: Sequence[ast.AST],\n    ) -> bool:\n        for right in comparators:\n            if isinstance(right, self._allowed_left_nodes):\n                return True\n            if isinstance(right, ast.BinOp):\n                return self._has_wrong_nodes_on_the_right([\n                    right.left, right.right,\n                ])\n        return False\n\n    def _check_ordering(self, node: ast.Compare) -> None:\n        if self._is_left_node_valid(node.left):\n            return\n\n        if self._is_special_case(node):\n            return\n\n        if len(node.comparators) > 1:\n            return\n\n        if not self._has_wrong_nodes_on_the_right(node.comparators):\n            return\n\n        self.add_violation(ComparisonOrderViolation(node))\n\n    def visit_Compare(self, node: ast.Compare) -> None:\n        \"\"\"\n        Forbids comparision where argument doesn't come first.\n\n        Raises:\n            ComparisonOrderViolation\n\n        \"\"\"\n        self._check_ordering(node)\n        self.generic_visit(node)\n\n\n# TODO(@sobolevn): refactor to be a single visitor\nclass MultipleInVisitor(BaseNodeVisitor):\n    \"\"\"Restricts comparision where multiple `in`s are used.\"\"\"\n\n    def _has_multiple_in_comparisons(self, node: ast.Compare) -> bool:\n        count = 0\n        for op in node.ops:\n            if isinstance(op, ast.In):\n                count += 1\n        return count > 1\n\n    def _count_in_comparisons(self, node: ast.Compare) -> None:\n        if self._has_multiple_in_comparisons(node):\n            self.add_violation(MultipleInComparisonViolation(node))\n\n    def visit_Compare(self, node: ast.Compare) -> None:\n        \"\"\"\n        Forbids comparisons including multiple 'in's in a statement.\n\n        Raise:\n            MultipleInComparisonViolation\n\n        \"\"\"\n        self._count_in_comparisons(node)\n        self.generic_visit(node)\n\n\nclass RedundantComparisonVisitor(BaseNodeVisitor):\n    \"\"\"Restricts the comparison where always same result.\"\"\"\n\n    def visit_Compare(self, node: ast.Compare) -> None:\n        \"\"\"\n        Ensures that compares are not for same variable.\n\n        Raises:\n            ConstantComparisonViolation\n\n        \"\"\"\n        self._check_redundant_compare(node)\n        self.generic_visit(node)\n\n    def _is_same_variable(self, left: ast.AST, right: ast.AST) -> bool:\n        if isinstance(left, ast.Name) and isinstance(right, ast.Name):\n            if left.id is right.id:\n                return True\n        return False\n\n    def _check_redundant_compare(self, node: ast.Compare) -> None:\n        last_variable = node.left\n        for next_variable in node.comparators:\n            if self._is_same_variable(last_variable, next_variable):\n                self.add_violation(ConstantComparisonViolation(node))\n                break\n            last_variable = next_variable\n", "path": "wemake_python_styleguide/visitors/ast/comparisons.py"}]}