-
I don't see why this error: from PythonInterface import Python
fn create_matrix(rows : Int, cols : Int) -> object:
# This is equivalent to Python's `import numpy as np`
let np = Python.import_module("numpy")
# Create matrix with numpy:
let matrix = np.arange(1, rows*cols+1).reshape(rows, cols)
return matrix
# Create matrix 9 rows and 5 cols:
print(create_matrix(9, 5)) error: Expression [18]:7:34: cannot call function that may raise in a context that cannot raise |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 4 replies
-
The issue here is that all calls through imported python APIs can raise an error at any time, but a 'fn' defaults not not being able to raise. Try switching create_matrix to being a def, or mark it "raises" |
Beta Was this translation helpful? Give feedback.
-
Thank you @lattner I added raises and now it works: from PythonInterface import Python
fn create_matrix(rows : Int, cols : Int) raises -> PythonObject:
# This is equivalent to Python's `import numpy as np`
let np = Python.import_module("numpy")
# Create matrix with numpy:
let matrix = np.arange(1, rows*cols+1).reshape(rows, cols)
return matrix
# Create matrix 9 rows and 5 cols:
print(create_matrix(9, 5)) |
Beta Was this translation helpful? Give feedback.
-
I had a similar issue on a Am I right to say that |
Beta Was this translation helpful? Give feedback.
-
I solved all my problems abandoning mojo for c++, mojo is undoubtedly an interesting project, even if it's a soup of multiple languages, but it's impossible to follow at the moment, it's too early stage and too confusing, even input doesn't work.. |
Beta Was this translation helpful? Give feedback.
The issue here is that all calls through imported python APIs can raise an error at any time, but a 'fn' defaults not not being able to raise. Try switching create_matrix to being a def, or mark it "raises"