-
Notifications
You must be signed in to change notification settings - Fork 760
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Async pymethods returning result breaks "new" initializer method #4502
Comments
So for your first snippet #[new]
-pub fn new() -> PyResult<()> {
+pub fn new() -> PyResult<Self> {
Err(PyTypeError::new_err("Some error of fallible __init__"))
} As for this compile errror:
Your error type has to be convertable into I think these are two independent problems, I currently don't seen any interaction between them. |
Agreed, and in both of these cases we can probably improve the span and/or emit a better diagnostic. |
Yes, here you are right, my bad. I was experimenting with !/Never at first position at the main code.
Hmmm, that's issue with my IDE (RustRover), because it does not shows errors about sync version, but issue still persists and causes compilation error. My fault, does not double check the compilation on both variants. |
Bug Description
If you create some async function returning
Result<T, E>
and then createnew
method, you will experience strange things. Look at first code snipet - it won't compile, then look at backtrace 1. Same with snippet 3.Removing "async" from function fixes the issue. According to macro expansions, something goes wrong at async function expansion.
Expanded code:
Even such variant fails:
Leads to
So there is no problem returning
PyErr
fromnew
, there is a connection between async function's Result second argument which must bePyErr
or must be convertable into it. I think this is a real issue and error atnew
is just a side effect.If this is intended (i can't find anything about return types of async functions at Using async and await ), i think more understandable error message should be provided instead of two misleading errors, because it is not easy to match error pointing to
new
method and return type of your async function.Steps to Reproduce
#[pyclass]
#[pymethods]
and#[new]
Result<Anything, Something>
.And that's it. After adding this, you always will see compilation error with such message:
Backtrace
Backtrace of expanded version:
The text was updated successfully, but these errors were encountered: