prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  There is a missing check for the "associativity" of the operators in the stacks/infix_to_postfix_conversion.py file.
  ### Repository commit
  
  11582943a555ae3b6a22938df6d3645b0327562e
  
  ### Python version (python --version)
  
  Python 3.10.6
  
  ### Dependencies version (pip freeze)
  
  astroid==2.11.3
  bcc==0.18.0
  black==22.3.0
  blinker==1.4
  Brlapi==0.8.3
  certifi==2020.6.20
  chardet==4.0.0
  
  
  ### Expected behavior
  
  Hi, In the [data_structures/stacks/infix_to_postfix_conversion.py](https://github.com/TheAlgorithms/Python/blob/master/data_structures/stacks/infix_to_postfix_conversion.py) file, when we pass `"2^3^2"` argument to the `infix_to_postfix` function, it should return `'2 3 2 ^ ^'` back. This results in number `512` which is the correct calculation.
  
  ### Actual behavior
  
  Currently `infix_to_postfix("2^3^2")` returns `'2 3 ^ 2 ^'` which is wrong. If we calculate it, it returns number `64`.
  
  The reason behind this is that currently we don't have any check for the "associativity" of the operators. In particular `^` operator causes problem here. It has `Right-To-Left` associativity. 
  There is a missing check for the "associativity" of the operators in the stacks/infix_to_postfix_conversion.py file.
  ### Repository commit
  
  11582943a555ae3b6a22938df6d3645b0327562e
  
  ### Python version (python --version)
  
  Python 3.10.6
  
  ### Dependencies version (pip freeze)
  
  astroid==2.11.3
  bcc==0.18.0
  black==22.3.0
  blinker==1.4
  Brlapi==0.8.3
  certifi==2020.6.20
  chardet==4.0.0
  
  
  ### Expected behavior
  
  Hi, In the [data_structures/stacks/infix_to_postfix_conversion.py](https://github.com/TheAlgorithms/Python/blob/master/data_structures/stacks/infix_to_postfix_conversion.py) file, when we pass `"2^3^2"` argument to the `infix_to_postfix` function, it should return `'2 3 2 ^ ^'` back. This results in number `512` which is the correct calculation.
  
  ### Actual behavior
  
  Currently `infix_to_postfix("2^3^2")` returns `'2 3 ^ 2 ^'` which is wrong. If we calculate it, it returns number `64`.
  
  The reason behind this is that currently we don't have any check for the "associativity" of the operators. In particular `^` operator causes problem here. It has `Right-To-Left` associativity. 
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `data_structures/stacks/infix_to_postfix_conversion.py`
  Content:
  ```
  1 """
  2 https://en.wikipedia.org/wiki/Infix_notation
  3 https://en.wikipedia.org/wiki/Reverse_Polish_notation
  4 https://en.wikipedia.org/wiki/Shunting-yard_algorithm
  5 """
  6 
  7 from .balanced_parentheses import balanced_parentheses
  8 from .stack import Stack
  9 
  10 
  11 def precedence(char: str) -> int:
  12     """
  13     Return integer value representing an operator's precedence, or
  14     order of operation.
  15     https://en.wikipedia.org/wiki/Order_of_operations
  16     """
  17     return {"+": 1, "-": 1, "*": 2, "/": 2, "^": 3}.get(char, -1)
  18 
  19 
  20 def infix_to_postfix(expression_str: str) -> str:
  21     """
  22     >>> infix_to_postfix("(1*(2+3)+4))")
  23     Traceback (most recent call last):
  24         ...
  25     ValueError: Mismatched parentheses
  26     >>> infix_to_postfix("")
  27     ''
  28     >>> infix_to_postfix("3+2")
  29     '3 2 +'
  30     >>> infix_to_postfix("(3+4)*5-6")
  31     '3 4 + 5 * 6 -'
  32     >>> infix_to_postfix("(1+2)*3/4-5")
  33     '1 2 + 3 * 4 / 5 -'
  34     >>> infix_to_postfix("a+b*c+(d*e+f)*g")
  35     'a b c * + d e * f + g * +'
  36     >>> infix_to_postfix("x^y/(5*z)+2")
  37     'x y ^ 5 z * / 2 +'
  38     """
  39     if not balanced_parentheses(expression_str):
  40         raise ValueError("Mismatched parentheses")
  41     stack: Stack[str] = Stack()
  42     postfix = []
  43     for char in expression_str:
  44         if char.isalpha() or char.isdigit():
  45             postfix.append(char)
  46         elif char == "(":
  47             stack.push(char)
  48         elif char == ")":
  49             while not stack.is_empty() and stack.peek() != "(":
  50                 postfix.append(stack.pop())
  51             stack.pop()
  52         else:
  53             while not stack.is_empty() and precedence(char) <= precedence(stack.peek()):
  54                 postfix.append(stack.pop())
  55             stack.push(char)
  56     while not stack.is_empty():
  57         postfix.append(stack.pop())
  58     return " ".join(postfix)
  59 
  60 
  61 if __name__ == "__main__":
  62     from doctest import testmod
  63 
  64     testmod()
  65     expression = "a+b*(c^d-e)^(f+g*h)-i"
  66 
  67     print("Infix to Postfix Notation demonstration:\n")
  68     print("Infix notation: " + expression)
  69     print("Postfix notation: " + infix_to_postfix(expression))
  70
  ```
  --- 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()
  
  ```
  
golden_diff: diff --git a/data_structures/stacks/infix_to_postfix_conversion.py b/data_structures/stacks/infix_to_postfix_conversion.py
  --- a/data_structures/stacks/infix_to_postfix_conversion.py
  +++ b/data_structures/stacks/infix_to_postfix_conversion.py
  @@ -4,9 +4,26 @@
   https://en.wikipedia.org/wiki/Shunting-yard_algorithm
   """
   
  +from typing import Literal
  +
   from .balanced_parentheses import balanced_parentheses
   from .stack import Stack
   
  +PRECEDENCES: dict[str, int] = {
  +    "+": 1,
  +    "-": 1,
  +    "*": 2,
  +    "/": 2,
  +    "^": 3,
  +}
  +ASSOCIATIVITIES: dict[str, Literal["LR", "RL"]] = {
  +    "+": "LR",
  +    "-": "LR",
  +    "*": "LR",
  +    "/": "LR",
  +    "^": "RL",
  +}
  +
   
   def precedence(char: str) -> int:
       """
  @@ -14,7 +31,15 @@
       order of operation.
       https://en.wikipedia.org/wiki/Order_of_operations
       """
  -    return {"+": 1, "-": 1, "*": 2, "/": 2, "^": 3}.get(char, -1)
  +    return PRECEDENCES.get(char, -1)
  +
  +
  +def associativity(char: str) -> Literal["LR", "RL"]:
  +    """
  +    Return the associativity of the operator `char`.
  +    https://en.wikipedia.org/wiki/Operator_associativity
  +    """
  +    return ASSOCIATIVITIES[char]
   
   
   def infix_to_postfix(expression_str: str) -> str:
  @@ -35,6 +60,8 @@
       'a b c * + d e * f + g * +'
       >>> infix_to_postfix("x^y/(5*z)+2")
       'x y ^ 5 z * / 2 +'
  +    >>> infix_to_postfix("2^3^2")
  +    '2 3 2 ^ ^'
       """
       if not balanced_parentheses(expression_str):
           raise ValueError("Mismatched parentheses")
  @@ -50,9 +77,26 @@
                   postfix.append(stack.pop())
               stack.pop()
           else:
  -            while not stack.is_empty() and precedence(char) <= precedence(stack.peek()):
  +            while True:
  +                if stack.is_empty():
  +                    stack.push(char)
  +                    break
  +
  +                char_precedence = precedence(char)
  +                tos_precedence = precedence(stack.peek())
  +
  +                if char_precedence > tos_precedence:
  +                    stack.push(char)
  +                    break
  +                if char_precedence < tos_precedence:
  +                    postfix.append(stack.pop())
  +                    continue
  +                # Precedences are equal
  +                if associativity(char) == "RL":
  +                    stack.push(char)
  +                    break
                   postfix.append(stack.pop())
  -            stack.push(char)
  +
       while not stack.is_empty():
           postfix.append(stack.pop())
       return " ".join(postfix)
  
verification_info: {"golden_diff": "diff --git a/data_structures/stacks/infix_to_postfix_conversion.py b/data_structures/stacks/infix_to_postfix_conversion.py\n--- a/data_structures/stacks/infix_to_postfix_conversion.py\n+++ b/data_structures/stacks/infix_to_postfix_conversion.py\n@@ -4,9 +4,26 @@\n https://en.wikipedia.org/wiki/Shunting-yard_algorithm\n \"\"\"\n \n+from typing import Literal\n+\n from .balanced_parentheses import balanced_parentheses\n from .stack import Stack\n \n+PRECEDENCES: dict[str, int] = {\n+    \"+\": 1,\n+    \"-\": 1,\n+    \"*\": 2,\n+    \"/\": 2,\n+    \"^\": 3,\n+}\n+ASSOCIATIVITIES: dict[str, Literal[\"LR\", \"RL\"]] = {\n+    \"+\": \"LR\",\n+    \"-\": \"LR\",\n+    \"*\": \"LR\",\n+    \"/\": \"LR\",\n+    \"^\": \"RL\",\n+}\n+\n \n def precedence(char: str) -> int:\n     \"\"\"\n@@ -14,7 +31,15 @@\n     order of operation.\n     https://en.wikipedia.org/wiki/Order_of_operations\n     \"\"\"\n-    return {\"+\": 1, \"-\": 1, \"*\": 2, \"/\": 2, \"^\": 3}.get(char, -1)\n+    return PRECEDENCES.get(char, -1)\n+\n+\n+def associativity(char: str) -> Literal[\"LR\", \"RL\"]:\n+    \"\"\"\n+    Return the associativity of the operator `char`.\n+    https://en.wikipedia.org/wiki/Operator_associativity\n+    \"\"\"\n+    return ASSOCIATIVITIES[char]\n \n \n def infix_to_postfix(expression_str: str) -> str:\n@@ -35,6 +60,8 @@\n     'a b c * + d e * f + g * +'\n     >>> infix_to_postfix(\"x^y/(5*z)+2\")\n     'x y ^ 5 z * / 2 +'\n+    >>> infix_to_postfix(\"2^3^2\")\n+    '2 3 2 ^ ^'\n     \"\"\"\n     if not balanced_parentheses(expression_str):\n         raise ValueError(\"Mismatched parentheses\")\n@@ -50,9 +77,26 @@\n                 postfix.append(stack.pop())\n             stack.pop()\n         else:\n-            while not stack.is_empty() and precedence(char) <= precedence(stack.peek()):\n+            while True:\n+                if stack.is_empty():\n+                    stack.push(char)\n+                    break\n+\n+                char_precedence = precedence(char)\n+                tos_precedence = precedence(stack.peek())\n+\n+                if char_precedence > tos_precedence:\n+                    stack.push(char)\n+                    break\n+                if char_precedence < tos_precedence:\n+                    postfix.append(stack.pop())\n+                    continue\n+                # Precedences are equal\n+                if associativity(char) == \"RL\":\n+                    stack.push(char)\n+                    break\n                 postfix.append(stack.pop())\n-            stack.push(char)\n+\n     while not stack.is_empty():\n         postfix.append(stack.pop())\n     return \" \".join(postfix)\n", "issue": "There is a missing check for the \"associativity\" of the operators in the stacks/infix_to_postfix_conversion.py file.\n### Repository commit\r\n\r\n11582943a555ae3b6a22938df6d3645b0327562e\r\n\r\n### Python version (python --version)\r\n\r\nPython 3.10.6\r\n\r\n### Dependencies version (pip freeze)\r\n\r\nastroid==2.11.3\r\nbcc==0.18.0\r\nblack==22.3.0\r\nblinker==1.4\r\nBrlapi==0.8.3\r\ncertifi==2020.6.20\r\nchardet==4.0.0\r\n\r\n\r\n### Expected behavior\r\n\r\nHi, In the [data_structures/stacks/infix_to_postfix_conversion.py](https://github.com/TheAlgorithms/Python/blob/master/data_structures/stacks/infix_to_postfix_conversion.py) file, when we pass `\"2^3^2\"` argument to the `infix_to_postfix` function, it should return `'2 3 2 ^ ^'` back. This results in number `512` which is the correct calculation.\r\n\r\n### Actual behavior\r\n\r\nCurrently `infix_to_postfix(\"2^3^2\")` returns `'2 3 ^ 2 ^'` which is wrong. If we calculate it, it returns number `64`.\r\n\r\nThe reason behind this is that currently we don't have any check for the \"associativity\" of the operators. In particular `^` operator causes problem here. It has `Right-To-Left` associativity. \nThere is a missing check for the \"associativity\" of the operators in the stacks/infix_to_postfix_conversion.py file.\n### Repository commit\r\n\r\n11582943a555ae3b6a22938df6d3645b0327562e\r\n\r\n### Python version (python --version)\r\n\r\nPython 3.10.6\r\n\r\n### Dependencies version (pip freeze)\r\n\r\nastroid==2.11.3\r\nbcc==0.18.0\r\nblack==22.3.0\r\nblinker==1.4\r\nBrlapi==0.8.3\r\ncertifi==2020.6.20\r\nchardet==4.0.0\r\n\r\n\r\n### Expected behavior\r\n\r\nHi, In the [data_structures/stacks/infix_to_postfix_conversion.py](https://github.com/TheAlgorithms/Python/blob/master/data_structures/stacks/infix_to_postfix_conversion.py) file, when we pass `\"2^3^2\"` argument to the `infix_to_postfix` function, it should return `'2 3 2 ^ ^'` back. This results in number `512` which is the correct calculation.\r\n\r\n### Actual behavior\r\n\r\nCurrently `infix_to_postfix(\"2^3^2\")` returns `'2 3 ^ 2 ^'` which is wrong. If we calculate it, it returns number `64`.\r\n\r\nThe reason behind this is that currently we don't have any check for the \"associativity\" of the operators. In particular `^` operator causes problem here. It has `Right-To-Left` associativity. \n", "before_files": [{"content": "\"\"\"\nhttps://en.wikipedia.org/wiki/Infix_notation\nhttps://en.wikipedia.org/wiki/Reverse_Polish_notation\nhttps://en.wikipedia.org/wiki/Shunting-yard_algorithm\n\"\"\"\n\nfrom .balanced_parentheses import balanced_parentheses\nfrom .stack import Stack\n\n\ndef precedence(char: str) -> int:\n    \"\"\"\n    Return integer value representing an operator's precedence, or\n    order of operation.\n    https://en.wikipedia.org/wiki/Order_of_operations\n    \"\"\"\n    return {\"+\": 1, \"-\": 1, \"*\": 2, \"/\": 2, \"^\": 3}.get(char, -1)\n\n\ndef infix_to_postfix(expression_str: str) -> str:\n    \"\"\"\n    >>> infix_to_postfix(\"(1*(2+3)+4))\")\n    Traceback (most recent call last):\n        ...\n    ValueError: Mismatched parentheses\n    >>> infix_to_postfix(\"\")\n    ''\n    >>> infix_to_postfix(\"3+2\")\n    '3 2 +'\n    >>> infix_to_postfix(\"(3+4)*5-6\")\n    '3 4 + 5 * 6 -'\n    >>> infix_to_postfix(\"(1+2)*3/4-5\")\n    '1 2 + 3 * 4 / 5 -'\n    >>> infix_to_postfix(\"a+b*c+(d*e+f)*g\")\n    'a b c * + d e * f + g * +'\n    >>> infix_to_postfix(\"x^y/(5*z)+2\")\n    'x y ^ 5 z * / 2 +'\n    \"\"\"\n    if not balanced_parentheses(expression_str):\n        raise ValueError(\"Mismatched parentheses\")\n    stack: Stack[str] = Stack()\n    postfix = []\n    for char in expression_str:\n        if char.isalpha() or char.isdigit():\n            postfix.append(char)\n        elif char == \"(\":\n            stack.push(char)\n        elif char == \")\":\n            while not stack.is_empty() and stack.peek() != \"(\":\n                postfix.append(stack.pop())\n            stack.pop()\n        else:\n            while not stack.is_empty() and precedence(char) <= precedence(stack.peek()):\n                postfix.append(stack.pop())\n            stack.push(char)\n    while not stack.is_empty():\n        postfix.append(stack.pop())\n    return \" \".join(postfix)\n\n\nif __name__ == \"__main__\":\n    from doctest import testmod\n\n    testmod()\n    expression = \"a+b*(c^d-e)^(f+g*h)-i\"\n\n    print(\"Infix to Postfix Notation demonstration:\\n\")\n    print(\"Infix notation: \" + expression)\n    print(\"Postfix notation: \" + infix_to_postfix(expression))\n", "path": "data_structures/stacks/infix_to_postfix_conversion.py"}], "after_files": [{"content": "\"\"\"\nhttps://en.wikipedia.org/wiki/Infix_notation\nhttps://en.wikipedia.org/wiki/Reverse_Polish_notation\nhttps://en.wikipedia.org/wiki/Shunting-yard_algorithm\n\"\"\"\n\nfrom typing import Literal\n\nfrom .balanced_parentheses import balanced_parentheses\nfrom .stack import Stack\n\nPRECEDENCES: dict[str, int] = {\n    \"+\": 1,\n    \"-\": 1,\n    \"*\": 2,\n    \"/\": 2,\n    \"^\": 3,\n}\nASSOCIATIVITIES: dict[str, Literal[\"LR\", \"RL\"]] = {\n    \"+\": \"LR\",\n    \"-\": \"LR\",\n    \"*\": \"LR\",\n    \"/\": \"LR\",\n    \"^\": \"RL\",\n}\n\n\ndef precedence(char: str) -> int:\n    \"\"\"\n    Return integer value representing an operator's precedence, or\n    order of operation.\n    https://en.wikipedia.org/wiki/Order_of_operations\n    \"\"\"\n    return PRECEDENCES.get(char, -1)\n\n\ndef associativity(char: str) -> Literal[\"LR\", \"RL\"]:\n    \"\"\"\n    Return the associativity of the operator `char`.\n    https://en.wikipedia.org/wiki/Operator_associativity\n    \"\"\"\n    return ASSOCIATIVITIES[char]\n\n\ndef infix_to_postfix(expression_str: str) -> str:\n    \"\"\"\n    >>> infix_to_postfix(\"(1*(2+3)+4))\")\n    Traceback (most recent call last):\n        ...\n    ValueError: Mismatched parentheses\n    >>> infix_to_postfix(\"\")\n    ''\n    >>> infix_to_postfix(\"3+2\")\n    '3 2 +'\n    >>> infix_to_postfix(\"(3+4)*5-6\")\n    '3 4 + 5 * 6 -'\n    >>> infix_to_postfix(\"(1+2)*3/4-5\")\n    '1 2 + 3 * 4 / 5 -'\n    >>> infix_to_postfix(\"a+b*c+(d*e+f)*g\")\n    'a b c * + d e * f + g * +'\n    >>> infix_to_postfix(\"x^y/(5*z)+2\")\n    'x y ^ 5 z * / 2 +'\n    >>> infix_to_postfix(\"2^3^2\")\n    '2 3 2 ^ ^'\n    \"\"\"\n    if not balanced_parentheses(expression_str):\n        raise ValueError(\"Mismatched parentheses\")\n    stack: Stack[str] = Stack()\n    postfix = []\n    for char in expression_str:\n        if char.isalpha() or char.isdigit():\n            postfix.append(char)\n        elif char == \"(\":\n            stack.push(char)\n        elif char == \")\":\n            while not stack.is_empty() and stack.peek() != \"(\":\n                postfix.append(stack.pop())\n            stack.pop()\n        else:\n            while True:\n                if stack.is_empty():\n                    stack.push(char)\n                    break\n\n                char_precedence = precedence(char)\n                tos_precedence = precedence(stack.peek())\n\n                if char_precedence > tos_precedence:\n                    stack.push(char)\n                    break\n                if char_precedence < tos_precedence:\n                    postfix.append(stack.pop())\n                    continue\n                # Precedences are equal\n                if associativity(char) == \"RL\":\n                    stack.push(char)\n                    break\n                postfix.append(stack.pop())\n\n    while not stack.is_empty():\n        postfix.append(stack.pop())\n    return \" \".join(postfix)\n\n\nif __name__ == \"__main__\":\n    from doctest import testmod\n\n    testmod()\n    expression = \"a+b*(c^d-e)^(f+g*h)-i\"\n\n    print(\"Infix to Postfix Notation demonstration:\\n\")\n    print(\"Infix notation: \" + expression)\n    print(\"Postfix notation: \" + infix_to_postfix(expression))\n", "path": "data_structures/stacks/infix_to_postfix_conversion.py"}]}