We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
`if` after `else` in `try` raises false positive WPS513
# Bug report

<!--
Hi, thanks for submitting a bug. We appreciate that.

But, we will need some information about what's wrong to help you.
-->

## What's wrong

Code:

```python
        try:
            return_value = ast.literal_eval(node.body)
        except ValueError:
            # The value was not literal, it's ok.
            return
        else:
            if return_value in self._primitive_values:
                self.add_violation(ImplicitPrimitiveViolation(node))
```

Output:

```
329:13   WPS513 Found implicit `elif` condition
  if return_value in self._primitive_values:
```

<!-- Describe what is not working. Please, attach a traceback. -->

## How is that should be

It should not raise this violation. It is not a part of `if` / `else` case.


--- 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/tokenize/conditions.py`
Content:
```
1 # -*- coding: utf-8 -*-
2 
3 import tokenize
4 from typing import ClassVar, FrozenSet
5 
6 from typing_extensions import final
7 
8 from wemake_python_styleguide.violations.refactoring import (
9     ImplicitElifViolation,
10 )
11 from wemake_python_styleguide.visitors.base import BaseTokenVisitor
12 
13 
14 @final
15 class IfElseVisitor(BaseTokenVisitor):
16     """
17     Checks if tokens tokens.
18 
19     We use ``tokenize`` instead of ``ast`` because
20 
21     .. code:: python
22 
23        if some:
24            ...
25         else:
26             if other:
27                 ...
28 
29     has the same ``ast`` representation as:
30 
31     .. code:: python
32 
33       if some:
34           ...
35       elif other:
36           ...
37 
38     That's why we have to use ``tokenize`` to find
39     the raw tokens inside the text.
40 
41     """
42 
43     _allowed_token_types: ClassVar[FrozenSet[int]] = frozenset((
44         tokenize.NEWLINE,
45         tokenize.NL,
46         tokenize.COLON,
47         tokenize.INDENT,
48     ))
49 
50     def visit_name(self, token: tokenize.TokenInfo) -> None:
51         """
52         Checks that ``if`` nodes are defined correctly.
53 
54         Raises:
55             ImplicitElifViolation
56 
57         """
58         self._check_implicit_elif(token)
59 
60     def _check_implicit_elif(self, token: tokenize.TokenInfo) -> None:
61         if token.string != 'else':
62             return
63 
64         index = self.file_tokens.index(token)
65         # There's a bug in coverage, I am not sure how to make it work.
66         for next_token in self.file_tokens[index + 1:]:  # pragma: no cover
67             if next_token.exact_type in self._allowed_token_types:
68                 continue
69             elif next_token.string == 'if':
70                 self.add_violation(ImplicitElifViolation(next_token))
71             return
72
```
--- 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/tokenize/conditions.py b/wemake_python_styleguide/visitors/tokenize/conditions.py
--- a/wemake_python_styleguide/visitors/tokenize/conditions.py
+++ b/wemake_python_styleguide/visitors/tokenize/conditions.py
@@ -57,11 +57,36 @@
         """
         self._check_implicit_elif(token)
 
+    def _does_else_belong_to_if(self, start_index: int) -> bool:
+        previous_token = self.file_tokens[start_index - 1]
+
+        if previous_token.type != tokenize.DEDENT:
+            # This is not the first token on the line, which means that it can
+            # also be "embedded" else: x if A else B
+            return False
+
+        for token in reversed(self.file_tokens[:start_index - 1]):
+            if token.type != tokenize.NAME:
+                continue
+
+            # Here we rely upon an intuition that in Python else have to be
+            # on the same level (same indentation) as parent statement.
+            if token.start[1] == previous_token.start[1]:
+                return token.string in {'if', 'elif'}
+
+        return False
+
     def _check_implicit_elif(self, token: tokenize.TokenInfo) -> None:
         if token.string != 'else':
             return
 
         index = self.file_tokens.index(token)
+
+        # `else` token can belong also to `for` and `try/except` statement,
+        # which can trigger false positive for that violation.
+        if not self._does_else_belong_to_if(index):
+            return
+
         # There's a bug in coverage, I am not sure how to make it work.
         for next_token in self.file_tokens[index + 1:]:  # pragma: no cover
             if next_token.exact_type in self._allowed_token_types:

{"golden_diff": "diff --git a/wemake_python_styleguide/visitors/tokenize/conditions.py b/wemake_python_styleguide/visitors/tokenize/conditions.py\n--- a/wemake_python_styleguide/visitors/tokenize/conditions.py\n+++ b/wemake_python_styleguide/visitors/tokenize/conditions.py\n@@ -57,11 +57,36 @@\n         \"\"\"\n         self._check_implicit_elif(token)\n \n+    def _does_else_belong_to_if(self, start_index: int) -> bool:\n+        previous_token = self.file_tokens[start_index - 1]\n+\n+        if previous_token.type != tokenize.DEDENT:\n+            # This is not the first token on the line, which means that it can\n+            # also be \"embedded\" else: x if A else B\n+            return False\n+\n+        for token in reversed(self.file_tokens[:start_index - 1]):\n+            if token.type != tokenize.NAME:\n+                continue\n+\n+            # Here we rely upon an intuition that in Python else have to be\n+            # on the same level (same indentation) as parent statement.\n+            if token.start[1] == previous_token.start[1]:\n+                return token.string in {'if', 'elif'}\n+\n+        return False\n+\n     def _check_implicit_elif(self, token: tokenize.TokenInfo) -> None:\n         if token.string != 'else':\n             return\n \n         index = self.file_tokens.index(token)\n+\n+        # `else` token can belong also to `for` and `try/except` statement,\n+        # which can trigger false positive for that violation.\n+        if not self._does_else_belong_to_if(index):\n+            return\n+\n         # There's a bug in coverage, I am not sure how to make it work.\n         for next_token in self.file_tokens[index + 1:]:  # pragma: no cover\n             if next_token.exact_type in self._allowed_token_types:\n", "issue": "`if` after `else` in `try` raises false positive WPS513\n# Bug report\r\n\r\n<!--\r\nHi, thanks for submitting a bug. We appreciate that.\r\n\r\nBut, we will need some information about what's wrong to help you.\r\n-->\r\n\r\n## What's wrong\r\n\r\nCode:\r\n\r\n```python\r\n        try:\r\n            return_value = ast.literal_eval(node.body)\r\n        except ValueError:\r\n            # The value was not literal, it's ok.\r\n            return\r\n        else:\r\n            if return_value in self._primitive_values:\r\n                self.add_violation(ImplicitPrimitiveViolation(node))\r\n```\r\n\r\nOutput:\r\n\r\n```\r\n329:13   WPS513 Found implicit `elif` condition\r\n  if return_value in self._primitive_values:\r\n```\r\n\r\n<!-- Describe what is not working. Please, attach a traceback. -->\r\n\r\n## How is that should be\r\n\r\nIt should not raise this violation. It is not a part of `if` / `else` case.\r\n\n", "before_files": [{"content": "# -*- coding: utf-8 -*-\n\nimport tokenize\nfrom typing import ClassVar, FrozenSet\n\nfrom typing_extensions import final\n\nfrom wemake_python_styleguide.violations.refactoring import (\n    ImplicitElifViolation,\n)\nfrom wemake_python_styleguide.visitors.base import BaseTokenVisitor\n\n\n@final\nclass IfElseVisitor(BaseTokenVisitor):\n    \"\"\"\n    Checks if tokens tokens.\n\n    We use ``tokenize`` instead of ``ast`` because\n\n    .. code:: python\n\n       if some:\n           ...\n        else:\n            if other:\n                ...\n\n    has the same ``ast`` representation as:\n\n    .. code:: python\n\n      if some:\n          ...\n      elif other:\n          ...\n\n    That's why we have to use ``tokenize`` to find\n    the raw tokens inside the text.\n\n    \"\"\"\n\n    _allowed_token_types: ClassVar[FrozenSet[int]] = frozenset((\n        tokenize.NEWLINE,\n        tokenize.NL,\n        tokenize.COLON,\n        tokenize.INDENT,\n    ))\n\n    def visit_name(self, token: tokenize.TokenInfo) -> None:\n        \"\"\"\n        Checks that ``if`` nodes are defined correctly.\n\n        Raises:\n            ImplicitElifViolation\n\n        \"\"\"\n        self._check_implicit_elif(token)\n\n    def _check_implicit_elif(self, token: tokenize.TokenInfo) -> None:\n        if token.string != 'else':\n            return\n\n        index = self.file_tokens.index(token)\n        # There's a bug in coverage, I am not sure how to make it work.\n        for next_token in self.file_tokens[index + 1:]:  # pragma: no cover\n            if next_token.exact_type in self._allowed_token_types:\n                continue\n            elif next_token.string == 'if':\n                self.add_violation(ImplicitElifViolation(next_token))\n            return\n", "path": "wemake_python_styleguide/visitors/tokenize/conditions.py"}], "after_files": [{"content": "# -*- coding: utf-8 -*-\n\nimport tokenize\nfrom typing import ClassVar, FrozenSet\n\nfrom typing_extensions import final\n\nfrom wemake_python_styleguide.violations.refactoring import (\n    ImplicitElifViolation,\n)\nfrom wemake_python_styleguide.visitors.base import BaseTokenVisitor\n\n\n@final\nclass IfElseVisitor(BaseTokenVisitor):\n    \"\"\"\n    Checks if tokens tokens.\n\n    We use ``tokenize`` instead of ``ast`` because\n\n    .. code:: python\n\n       if some:\n           ...\n        else:\n            if other:\n                ...\n\n    has the same ``ast`` representation as:\n\n    .. code:: python\n\n      if some:\n          ...\n      elif other:\n          ...\n\n    That's why we have to use ``tokenize`` to find\n    the raw tokens inside the text.\n\n    \"\"\"\n\n    _allowed_token_types: ClassVar[FrozenSet[int]] = frozenset((\n        tokenize.NEWLINE,\n        tokenize.NL,\n        tokenize.COLON,\n        tokenize.INDENT,\n    ))\n\n    def visit_name(self, token: tokenize.TokenInfo) -> None:\n        \"\"\"\n        Checks that ``if`` nodes are defined correctly.\n\n        Raises:\n            ImplicitElifViolation\n\n        \"\"\"\n        self._check_implicit_elif(token)\n\n    def _does_else_belong_to_if(self, start_index: int) -> bool:\n        previous_token = self.file_tokens[start_index - 1]\n\n        if previous_token.type != tokenize.DEDENT:\n            # This is not the first token on the line, which means that it can\n            # also be \"embedded\" else: x if A else B\n            return False\n\n        for token in reversed(self.file_tokens[:start_index - 1]):\n            if token.type != tokenize.NAME:\n                continue\n\n            # Here we rely upon an intuition that in Python else have to be\n            # on the same level (same indentation) as parent statement.\n            if token.start[1] == previous_token.start[1]:\n                return token.string in {'if', 'elif'}\n\n        return False\n\n    def _check_implicit_elif(self, token: tokenize.TokenInfo) -> None:\n        if token.string != 'else':\n            return\n\n        index = self.file_tokens.index(token)\n\n        # `else` token can belong also to `for` and `try/except` statement,\n        # which can trigger false positive for that violation.\n        if not self._does_else_belong_to_if(index):\n            return\n\n        # There's a bug in coverage, I am not sure how to make it work.\n        for next_token in self.file_tokens[index + 1:]:  # pragma: no cover\n            if next_token.exact_type in self._allowed_token_types:\n                continue\n            elif next_token.string == 'if':\n                self.add_violation(ImplicitElifViolation(next_token))\n            return\n", "path": "wemake_python_styleguide/visitors/tokenize/conditions.py"}]}