prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Convert function takes string instead of type for conversion to
  ### What's your issue about?
  If you forget to add quotes to the type you want to convert to, Vyper will give an unhelpful error:
  ```python
  convert(some_int128, uint256)
  # raises:
  #    AttributeError: 'Name' object has no attribute 's'
  ```
  
  ### How can it be fixed?
  So, catching this error might work out to fix this issue, but I think the underlying issue is that the second argument (`convertTo`) is a string instead of a typename. This actually makes it a little more unintuitive to write conversions as you could misspell the name and not get visual feedback from your IDE (assuming you have syntax highlighting up)
  
  I would suggest turning this into a VIP to modify the syntax of convert such that a valid typename is supplied as the second argument
  
  #### Cute Animal Picture
  ![pony](https://upload.wikimedia.org/wikipedia/commons/thumb/8/8e/Gracie-rhs2005.jpg/1200px-Gracie-rhs2005.jpg)
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `vyper/types/convert.py`
  Content:
  ```
  1 from vyper.functions.signature import (
  2     signature
  3 )
  4 from vyper.parser.parser_utils import (
  5     LLLnode,
  6     getpos,
  7     byte_array_to_num
  8 )
  9 from vyper.exceptions import (
  10     InvalidLiteralException,
  11     TypeMismatchException,
  12 )
  13 from vyper.types import (
  14     BaseType,
  15 )
  16 from vyper.types import (
  17     get_type,
  18 )
  19 from vyper.utils import (
  20     DECIMAL_DIVISOR,
  21     MemoryPositions,
  22     SizeLimits
  23 )
  24 
  25 
  26 @signature(('uint256', 'bytes32', 'bytes'), 'str_literal')
  27 def to_int128(expr, args, kwargs, context):
  28     in_node = args[0]
  29     typ, len = get_type(in_node)
  30     if typ in ('uint256', 'bytes32'):
  31         if in_node.typ.is_literal and not SizeLimits.in_bounds('int128', in_node.value):
  32             raise InvalidLiteralException("Number out of range: {}".format(in_node.value), expr)
  33         return LLLnode.from_list(
  34             ['clamp', ['mload', MemoryPositions.MINNUM], in_node,
  35                         ['mload', MemoryPositions.MAXNUM]], typ=BaseType('int128', in_node.typ.unit), pos=getpos(expr)
  36         )
  37     else:
  38         return byte_array_to_num(in_node, expr, 'int128')
  39 
  40 
  41 @signature(('num_literal', 'int128', 'bytes32', 'address'), 'str_literal')
  42 def to_uint256(expr, args, kwargs, context):
  43     in_node = args[0]
  44     input_type, len = get_type(in_node)
  45 
  46     if isinstance(in_node, int):
  47         if not SizeLimits.in_bounds('uint256', in_node):
  48             raise InvalidLiteralException("Number out of range: {}".format(in_node))
  49         _unit = in_node.typ.unit if input_type == 'int128' else None
  50         return LLLnode.from_list(in_node, typ=BaseType('uint256', _unit), pos=getpos(expr))
  51 
  52     elif isinstance(in_node, LLLnode) and input_type in ('int128', 'num_literal'):
  53         _unit = in_node.typ.unit if input_type == 'int128' else None
  54         return LLLnode.from_list(['clampge', in_node, 0], typ=BaseType('uint256', _unit), pos=getpos(expr))
  55 
  56     elif isinstance(in_node, LLLnode) and input_type in ('bytes32', 'address'):
  57         return LLLnode(value=in_node.value, args=in_node.args, typ=BaseType('uint256'), pos=getpos(expr))
  58 
  59     else:
  60         raise InvalidLiteralException("Invalid input for uint256: %r" % in_node, expr)
  61 
  62 
  63 @signature(('int128', 'uint256'), 'str_literal')
  64 def to_decimal(expr, args, kwargs, context):
  65     input = args[0]
  66     if input.typ.typ == 'uint256':
  67         return LLLnode.from_list(
  68             ['uclample', ['mul', input, DECIMAL_DIVISOR], ['mload', MemoryPositions.MAXDECIMAL]],
  69             typ=BaseType('decimal', input.typ.unit, input.typ.positional), pos=getpos(expr)
  70         )
  71     else:
  72         return LLLnode.from_list(
  73             ['mul', input, DECIMAL_DIVISOR],
  74             typ=BaseType('decimal', input.typ.unit, input.typ.positional),
  75             pos=getpos(expr)
  76         )
  77 
  78 
  79 @signature(('int128', 'uint256', 'address', 'bytes'), 'str_literal')
  80 def to_bytes32(expr, args, kwargs, context):
  81     input = args[0]
  82     typ, len = get_type(input)
  83     if typ == 'bytes':
  84         if len != 32:
  85             raise TypeMismatchException("Unable to convert bytes[{}] to bytes32".format(len))
  86         if input.location == "memory":
  87             return LLLnode.from_list(
  88             ['mload', ['add', input, 32]], typ=BaseType('bytes32')
  89             )
  90         elif input.location == "storage":
  91             return LLLnode.from_list(
  92                 ['sload', ['add', ['sha3_32', input], 1]], typ=BaseType('bytes32')
  93             )
  94     else:
  95         return LLLnode(value=input.value, args=input.args, typ=BaseType('bytes32'), pos=getpos(expr))
  96 
  97 
  98 def convert(expr, context):
  99     output_type = expr.args[1].s
  100     if output_type in conversion_table:
  101         return conversion_table[output_type](expr, context)
  102     else:
  103         raise Exception("Conversion to {} is invalid.".format(output_type))
  104 
  105 
  106 conversion_table = {
  107     'int128': to_int128,
  108     'uint256': to_uint256,
  109     'decimal': to_decimal,
  110     'bytes32': to_bytes32,
  111 }
  112
  ```
  --- 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/vyper/types/convert.py b/vyper/types/convert.py
  --- a/vyper/types/convert.py
  +++ b/vyper/types/convert.py
  @@ -1,3 +1,6 @@
  +import ast
  +import warnings
  +
   from vyper.functions.signature import (
       signature
   )
  @@ -9,6 +12,7 @@
   from vyper.exceptions import (
       InvalidLiteralException,
       TypeMismatchException,
  +    ParserException,
   )
   from vyper.types import (
       BaseType,
  @@ -23,7 +27,7 @@
   )
   
   
  -@signature(('uint256', 'bytes32', 'bytes'), 'str_literal')
  +@signature(('uint256', 'bytes32', 'bytes'), '*')
   def to_int128(expr, args, kwargs, context):
       in_node = args[0]
       typ, len = get_type(in_node)
  @@ -38,7 +42,7 @@
           return byte_array_to_num(in_node, expr, 'int128')
   
   
  -@signature(('num_literal', 'int128', 'bytes32', 'address'), 'str_literal')
  +@signature(('num_literal', 'int128', 'bytes32', 'address'), '*')
   def to_uint256(expr, args, kwargs, context):
       in_node = args[0]
       input_type, len = get_type(in_node)
  @@ -60,7 +64,7 @@
           raise InvalidLiteralException("Invalid input for uint256: %r" % in_node, expr)
   
   
  -@signature(('int128', 'uint256'), 'str_literal')
  +@signature(('int128', 'uint256'), '*')
   def to_decimal(expr, args, kwargs, context):
       input = args[0]
       if input.typ.typ == 'uint256':
  @@ -76,7 +80,7 @@
           )
   
   
  -@signature(('int128', 'uint256', 'address', 'bytes'), 'str_literal')
  +@signature(('int128', 'uint256', 'address', 'bytes'), '*')
   def to_bytes32(expr, args, kwargs, context):
       input = args[0]
       typ, len = get_type(input)
  @@ -96,11 +100,23 @@
   
   
   def convert(expr, context):
  -    output_type = expr.args[1].s
  +
  +    if isinstance(expr.args[1], ast.Str):
  +        warnings.warn(
  +            "String parameter has been removed, see VIP1026). "
  +            "Use a vyper type instead.",
  +            DeprecationWarning
  +        )
  +
  +    if isinstance(expr.args[1], ast.Name):
  +        output_type = expr.args[1].id
  +    else:
  +        raise ParserException("Invalid conversion type, use valid vyper type.", expr)
  +
       if output_type in conversion_table:
           return conversion_table[output_type](expr, context)
       else:
  -        raise Exception("Conversion to {} is invalid.".format(output_type))
  +        raise ParserException("Conversion to {} is invalid.".format(output_type), expr)
   
   
   conversion_table = {
  
verification_info: {"golden_diff": "diff --git a/vyper/types/convert.py b/vyper/types/convert.py\n--- a/vyper/types/convert.py\n+++ b/vyper/types/convert.py\n@@ -1,3 +1,6 @@\n+import ast\n+import warnings\n+\n from vyper.functions.signature import (\n     signature\n )\n@@ -9,6 +12,7 @@\n from vyper.exceptions import (\n     InvalidLiteralException,\n     TypeMismatchException,\n+    ParserException,\n )\n from vyper.types import (\n     BaseType,\n@@ -23,7 +27,7 @@\n )\n \n \n-@signature(('uint256', 'bytes32', 'bytes'), 'str_literal')\n+@signature(('uint256', 'bytes32', 'bytes'), '*')\n def to_int128(expr, args, kwargs, context):\n     in_node = args[0]\n     typ, len = get_type(in_node)\n@@ -38,7 +42,7 @@\n         return byte_array_to_num(in_node, expr, 'int128')\n \n \n-@signature(('num_literal', 'int128', 'bytes32', 'address'), 'str_literal')\n+@signature(('num_literal', 'int128', 'bytes32', 'address'), '*')\n def to_uint256(expr, args, kwargs, context):\n     in_node = args[0]\n     input_type, len = get_type(in_node)\n@@ -60,7 +64,7 @@\n         raise InvalidLiteralException(\"Invalid input for uint256: %r\" % in_node, expr)\n \n \n-@signature(('int128', 'uint256'), 'str_literal')\n+@signature(('int128', 'uint256'), '*')\n def to_decimal(expr, args, kwargs, context):\n     input = args[0]\n     if input.typ.typ == 'uint256':\n@@ -76,7 +80,7 @@\n         )\n \n \n-@signature(('int128', 'uint256', 'address', 'bytes'), 'str_literal')\n+@signature(('int128', 'uint256', 'address', 'bytes'), '*')\n def to_bytes32(expr, args, kwargs, context):\n     input = args[0]\n     typ, len = get_type(input)\n@@ -96,11 +100,23 @@\n \n \n def convert(expr, context):\n-    output_type = expr.args[1].s\n+\n+    if isinstance(expr.args[1], ast.Str):\n+        warnings.warn(\n+            \"String parameter has been removed, see VIP1026). \"\n+            \"Use a vyper type instead.\",\n+            DeprecationWarning\n+        )\n+\n+    if isinstance(expr.args[1], ast.Name):\n+        output_type = expr.args[1].id\n+    else:\n+        raise ParserException(\"Invalid conversion type, use valid vyper type.\", expr)\n+\n     if output_type in conversion_table:\n         return conversion_table[output_type](expr, context)\n     else:\n-        raise Exception(\"Conversion to {} is invalid.\".format(output_type))\n+        raise ParserException(\"Conversion to {} is invalid.\".format(output_type), expr)\n \n \n conversion_table = {\n", "issue": "Convert function takes string instead of type for conversion to\n### What's your issue about?\r\nIf you forget to add quotes to the type you want to convert to, Vyper will give an unhelpful error:\r\n```python\r\nconvert(some_int128, uint256)\r\n# raises:\r\n#    AttributeError: 'Name' object has no attribute 's'\r\n```\r\n\r\n### How can it be fixed?\r\nSo, catching this error might work out to fix this issue, but I think the underlying issue is that the second argument (`convertTo`) is a string instead of a typename. This actually makes it a little more unintuitive to write conversions as you could misspell the name and not get visual feedback from your IDE (assuming you have syntax highlighting up)\r\n\r\nI would suggest turning this into a VIP to modify the syntax of convert such that a valid typename is supplied as the second argument\r\n\r\n#### Cute Animal Picture\r\n![pony](https://upload.wikimedia.org/wikipedia/commons/thumb/8/8e/Gracie-rhs2005.jpg/1200px-Gracie-rhs2005.jpg)\r\n\n", "before_files": [{"content": "from vyper.functions.signature import (\n    signature\n)\nfrom vyper.parser.parser_utils import (\n    LLLnode,\n    getpos,\n    byte_array_to_num\n)\nfrom vyper.exceptions import (\n    InvalidLiteralException,\n    TypeMismatchException,\n)\nfrom vyper.types import (\n    BaseType,\n)\nfrom vyper.types import (\n    get_type,\n)\nfrom vyper.utils import (\n    DECIMAL_DIVISOR,\n    MemoryPositions,\n    SizeLimits\n)\n\n\n@signature(('uint256', 'bytes32', 'bytes'), 'str_literal')\ndef to_int128(expr, args, kwargs, context):\n    in_node = args[0]\n    typ, len = get_type(in_node)\n    if typ in ('uint256', 'bytes32'):\n        if in_node.typ.is_literal and not SizeLimits.in_bounds('int128', in_node.value):\n            raise InvalidLiteralException(\"Number out of range: {}\".format(in_node.value), expr)\n        return LLLnode.from_list(\n            ['clamp', ['mload', MemoryPositions.MINNUM], in_node,\n                        ['mload', MemoryPositions.MAXNUM]], typ=BaseType('int128', in_node.typ.unit), pos=getpos(expr)\n        )\n    else:\n        return byte_array_to_num(in_node, expr, 'int128')\n\n\n@signature(('num_literal', 'int128', 'bytes32', 'address'), 'str_literal')\ndef to_uint256(expr, args, kwargs, context):\n    in_node = args[0]\n    input_type, len = get_type(in_node)\n\n    if isinstance(in_node, int):\n        if not SizeLimits.in_bounds('uint256', in_node):\n            raise InvalidLiteralException(\"Number out of range: {}\".format(in_node))\n        _unit = in_node.typ.unit if input_type == 'int128' else None\n        return LLLnode.from_list(in_node, typ=BaseType('uint256', _unit), pos=getpos(expr))\n\n    elif isinstance(in_node, LLLnode) and input_type in ('int128', 'num_literal'):\n        _unit = in_node.typ.unit if input_type == 'int128' else None\n        return LLLnode.from_list(['clampge', in_node, 0], typ=BaseType('uint256', _unit), pos=getpos(expr))\n\n    elif isinstance(in_node, LLLnode) and input_type in ('bytes32', 'address'):\n        return LLLnode(value=in_node.value, args=in_node.args, typ=BaseType('uint256'), pos=getpos(expr))\n\n    else:\n        raise InvalidLiteralException(\"Invalid input for uint256: %r\" % in_node, expr)\n\n\n@signature(('int128', 'uint256'), 'str_literal')\ndef to_decimal(expr, args, kwargs, context):\n    input = args[0]\n    if input.typ.typ == 'uint256':\n        return LLLnode.from_list(\n            ['uclample', ['mul', input, DECIMAL_DIVISOR], ['mload', MemoryPositions.MAXDECIMAL]],\n            typ=BaseType('decimal', input.typ.unit, input.typ.positional), pos=getpos(expr)\n        )\n    else:\n        return LLLnode.from_list(\n            ['mul', input, DECIMAL_DIVISOR],\n            typ=BaseType('decimal', input.typ.unit, input.typ.positional),\n            pos=getpos(expr)\n        )\n\n\n@signature(('int128', 'uint256', 'address', 'bytes'), 'str_literal')\ndef to_bytes32(expr, args, kwargs, context):\n    input = args[0]\n    typ, len = get_type(input)\n    if typ == 'bytes':\n        if len != 32:\n            raise TypeMismatchException(\"Unable to convert bytes[{}] to bytes32\".format(len))\n        if input.location == \"memory\":\n            return LLLnode.from_list(\n            ['mload', ['add', input, 32]], typ=BaseType('bytes32')\n            )\n        elif input.location == \"storage\":\n            return LLLnode.from_list(\n                ['sload', ['add', ['sha3_32', input], 1]], typ=BaseType('bytes32')\n            )\n    else:\n        return LLLnode(value=input.value, args=input.args, typ=BaseType('bytes32'), pos=getpos(expr))\n\n\ndef convert(expr, context):\n    output_type = expr.args[1].s\n    if output_type in conversion_table:\n        return conversion_table[output_type](expr, context)\n    else:\n        raise Exception(\"Conversion to {} is invalid.\".format(output_type))\n\n\nconversion_table = {\n    'int128': to_int128,\n    'uint256': to_uint256,\n    'decimal': to_decimal,\n    'bytes32': to_bytes32,\n}\n", "path": "vyper/types/convert.py"}], "after_files": [{"content": "import ast\nimport warnings\n\nfrom vyper.functions.signature import (\n    signature\n)\nfrom vyper.parser.parser_utils import (\n    LLLnode,\n    getpos,\n    byte_array_to_num\n)\nfrom vyper.exceptions import (\n    InvalidLiteralException,\n    TypeMismatchException,\n    ParserException,\n)\nfrom vyper.types import (\n    BaseType,\n)\nfrom vyper.types import (\n    get_type,\n)\nfrom vyper.utils import (\n    DECIMAL_DIVISOR,\n    MemoryPositions,\n    SizeLimits\n)\n\n\n@signature(('uint256', 'bytes32', 'bytes'), '*')\ndef to_int128(expr, args, kwargs, context):\n    in_node = args[0]\n    typ, len = get_type(in_node)\n    if typ in ('uint256', 'bytes32'):\n        if in_node.typ.is_literal and not SizeLimits.in_bounds('int128', in_node.value):\n            raise InvalidLiteralException(\"Number out of range: {}\".format(in_node.value), expr)\n        return LLLnode.from_list(\n            ['clamp', ['mload', MemoryPositions.MINNUM], in_node,\n                        ['mload', MemoryPositions.MAXNUM]], typ=BaseType('int128', in_node.typ.unit), pos=getpos(expr)\n        )\n    else:\n        return byte_array_to_num(in_node, expr, 'int128')\n\n\n@signature(('num_literal', 'int128', 'bytes32', 'address'), '*')\ndef to_uint256(expr, args, kwargs, context):\n    in_node = args[0]\n    input_type, len = get_type(in_node)\n\n    if isinstance(in_node, int):\n        if not SizeLimits.in_bounds('uint256', in_node):\n            raise InvalidLiteralException(\"Number out of range: {}\".format(in_node))\n        _unit = in_node.typ.unit if input_type == 'int128' else None\n        return LLLnode.from_list(in_node, typ=BaseType('uint256', _unit), pos=getpos(expr))\n\n    elif isinstance(in_node, LLLnode) and input_type in ('int128', 'num_literal'):\n        _unit = in_node.typ.unit if input_type == 'int128' else None\n        return LLLnode.from_list(['clampge', in_node, 0], typ=BaseType('uint256', _unit), pos=getpos(expr))\n\n    elif isinstance(in_node, LLLnode) and input_type in ('bytes32', 'address'):\n        return LLLnode(value=in_node.value, args=in_node.args, typ=BaseType('uint256'), pos=getpos(expr))\n\n    else:\n        raise InvalidLiteralException(\"Invalid input for uint256: %r\" % in_node, expr)\n\n\n@signature(('int128', 'uint256'), '*')\ndef to_decimal(expr, args, kwargs, context):\n    input = args[0]\n    if input.typ.typ == 'uint256':\n        return LLLnode.from_list(\n            ['uclample', ['mul', input, DECIMAL_DIVISOR], ['mload', MemoryPositions.MAXDECIMAL]],\n            typ=BaseType('decimal', input.typ.unit, input.typ.positional), pos=getpos(expr)\n        )\n    else:\n        return LLLnode.from_list(\n            ['mul', input, DECIMAL_DIVISOR],\n            typ=BaseType('decimal', input.typ.unit, input.typ.positional),\n            pos=getpos(expr)\n        )\n\n\n@signature(('int128', 'uint256', 'address', 'bytes'), '*')\ndef to_bytes32(expr, args, kwargs, context):\n    input = args[0]\n    typ, len = get_type(input)\n    if typ == 'bytes':\n        if len != 32:\n            raise TypeMismatchException(\"Unable to convert bytes[{}] to bytes32\".format(len))\n        if input.location == \"memory\":\n            return LLLnode.from_list(\n            ['mload', ['add', input, 32]], typ=BaseType('bytes32')\n            )\n        elif input.location == \"storage\":\n            return LLLnode.from_list(\n                ['sload', ['add', ['sha3_32', input], 1]], typ=BaseType('bytes32')\n            )\n    else:\n        return LLLnode(value=input.value, args=input.args, typ=BaseType('bytes32'), pos=getpos(expr))\n\n\ndef convert(expr, context):\n\n    if isinstance(expr.args[1], ast.Str):\n        warnings.warn(\n            \"String parameter has been removed, see VIP1026). \"\n            \"Use a vyper type instead.\",\n            DeprecationWarning\n        )\n\n    if isinstance(expr.args[1], ast.Name):\n        output_type = expr.args[1].id\n    else:\n        raise ParserException(\"Invalid conversion type, use valid vyper type.\", expr)\n\n    if output_type in conversion_table:\n        return conversion_table[output_type](expr, context)\n    else:\n        raise ParserException(\"Conversion to {} is invalid.\".format(output_type), expr)\n\n\nconversion_table = {\n    'int128': to_int128,\n    'uint256': to_uint256,\n    'decimal': to_decimal,\n    'bytes32': to_bytes32,\n}\n", "path": "vyper/types/convert.py"}]}