prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  ValueError: invalid __array_struct__ when using js arrays of arrays and numpy
  When using a matrix (array of array of numbers) in javascript and trying to convert that to a numpy array, it fails with the error `ValueError: invalid __array_struct__`
  
  To reproduce:
  JavaScript:
  ```
  window.A = [[1,2,3],[4,5,6]];
  ```
  Python:
  ```
  import numpy
  from js import A
  m = numpy.array(A)
  ```
  
  </issue>
  <code>
  [start of src/pyodide.py]
  1 """
  2 A library of helper utilities for connecting Python to the browser environment.
  3 """
  4 
  5 import ast
  6 import io
  7 from textwrap import dedent
  8 
  9 __version__ = '0.8.2'
  10 
  11 
  12 def open_url(url):
  13     """
  14     Fetches a given *url* and returns a io.StringIO to access its contents.
  15     """
  16     from js import XMLHttpRequest
  17 
  18     req = XMLHttpRequest.new()
  19     req.open('GET', url, False)
  20     req.send(None)
  21     return io.StringIO(req.response)
  22 
  23 
  24 def eval_code(code, ns):
  25     """
  26     Runs a string of code, the last part of which may be an expression.
  27     """
  28     # handle mis-indented input from multi-line strings
  29     code = dedent(code)
  30 
  31     mod = ast.parse(code)
  32     if len(mod.body) == 0:
  33         return None
  34 
  35     if isinstance(mod.body[-1], ast.Expr):
  36         expr = ast.Expression(mod.body[-1].value)
  37         del mod.body[-1]
  38     else:
  39         expr = None
  40 
  41     if len(mod.body):
  42         exec(compile(mod, '<exec>', mode='exec'), ns, ns)
  43     if expr is not None:
  44         return eval(compile(expr, '<eval>', mode='eval'), ns, ns)
  45     else:
  46         return None
  47 
  48 
  49 def find_imports(code):
  50     """
  51     Finds the imports in a string of code and returns a list of their package
  52     names.
  53     """
  54     # handle mis-indented input from multi-line strings
  55     code = dedent(code)
  56 
  57     mod = ast.parse(code)
  58     imports = set()
  59     for node in ast.walk(mod):
  60         if isinstance(node, ast.Import):
  61             for name in node.names:
  62                 name = name.name
  63                 imports.add(name.split('.')[0])
  64         elif isinstance(node, ast.ImportFrom):
  65             name = node.module
  66             imports.add(name.split('.')[0])
  67     return list(imports)
  68 
  69 
  70 __all__ = ['open_url', 'eval_code', 'find_imports']
  71
  [end of src/pyodide.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/src/pyodide.py b/src/pyodide.py
  --- a/src/pyodide.py
  +++ b/src/pyodide.py
  @@ -67,4 +67,16 @@
       return list(imports)
   
   
  -__all__ = ['open_url', 'eval_code', 'find_imports']
  +def as_nested_list(obj):
  +    """
  +    Assumes a Javascript object is made of (possibly nested) arrays and
  +    converts them to nested Python lists.
  +    """
  +    try:
  +        it = iter(obj)
  +        return [as_nested_list(x) for x in it]
  +    except TypeError:
  +        return obj
  +
  +
  +__all__ = ['open_url', 'eval_code', 'find_imports', 'as_nested_list']
  
verification_info: {"golden_diff": "diff --git a/src/pyodide.py b/src/pyodide.py\n--- a/src/pyodide.py\n+++ b/src/pyodide.py\n@@ -67,4 +67,16 @@\n     return list(imports)\n \n \n-__all__ = ['open_url', 'eval_code', 'find_imports']\n+def as_nested_list(obj):\n+    \"\"\"\n+    Assumes a Javascript object is made of (possibly nested) arrays and\n+    converts them to nested Python lists.\n+    \"\"\"\n+    try:\n+        it = iter(obj)\n+        return [as_nested_list(x) for x in it]\n+    except TypeError:\n+        return obj\n+\n+\n+__all__ = ['open_url', 'eval_code', 'find_imports', 'as_nested_list']\n", "issue": "ValueError: invalid __array_struct__ when using js arrays of arrays and numpy\nWhen using a matrix (array of array of numbers) in javascript and trying to convert that to a numpy array, it fails with the error `ValueError: invalid __array_struct__`\r\n\r\nTo reproduce:\r\nJavaScript:\r\n```\r\nwindow.A = [[1,2,3],[4,5,6]];\r\n```\r\nPython:\r\n```\r\nimport numpy\r\nfrom js import A\r\nm = numpy.array(A)\r\n```\n", "before_files": [{"content": "\"\"\"\nA library of helper utilities for connecting Python to the browser environment.\n\"\"\"\n\nimport ast\nimport io\nfrom textwrap import dedent\n\n__version__ = '0.8.2'\n\n\ndef open_url(url):\n    \"\"\"\n    Fetches a given *url* and returns a io.StringIO to access its contents.\n    \"\"\"\n    from js import XMLHttpRequest\n\n    req = XMLHttpRequest.new()\n    req.open('GET', url, False)\n    req.send(None)\n    return io.StringIO(req.response)\n\n\ndef eval_code(code, ns):\n    \"\"\"\n    Runs a string of code, the last part of which may be an expression.\n    \"\"\"\n    # handle mis-indented input from multi-line strings\n    code = dedent(code)\n\n    mod = ast.parse(code)\n    if len(mod.body) == 0:\n        return None\n\n    if isinstance(mod.body[-1], ast.Expr):\n        expr = ast.Expression(mod.body[-1].value)\n        del mod.body[-1]\n    else:\n        expr = None\n\n    if len(mod.body):\n        exec(compile(mod, '<exec>', mode='exec'), ns, ns)\n    if expr is not None:\n        return eval(compile(expr, '<eval>', mode='eval'), ns, ns)\n    else:\n        return None\n\n\ndef find_imports(code):\n    \"\"\"\n    Finds the imports in a string of code and returns a list of their package\n    names.\n    \"\"\"\n    # handle mis-indented input from multi-line strings\n    code = dedent(code)\n\n    mod = ast.parse(code)\n    imports = set()\n    for node in ast.walk(mod):\n        if isinstance(node, ast.Import):\n            for name in node.names:\n                name = name.name\n                imports.add(name.split('.')[0])\n        elif isinstance(node, ast.ImportFrom):\n            name = node.module\n            imports.add(name.split('.')[0])\n    return list(imports)\n\n\n__all__ = ['open_url', 'eval_code', 'find_imports']\n", "path": "src/pyodide.py"}]}