prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <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.
  
  
  </issue>
  <code>
  [start of wemake_python_styleguide/visitors/tokenize/conditions.py]
  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 of wemake_python_styleguide/visitors/tokenize/conditions.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: 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:
  
verification_info: {"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"}]}