-
Notifications
You must be signed in to change notification settings - Fork 783
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
Rework exceptions to be native types #1024
Conversation
Thank you, looks good except the approach to the breaking change(i.e., Py prefix) 🤔 |
I think any alternative, including the above, would break more user code than this PR already does. The simplest alternative would be to embrace the breaking change and just remove the old types. |
If you think it's okay, I would be very happy to do this. It keeps the pyo3 codebase smaller and I can document these breaking changes immediately in the migration guide. |
5ade30e
to
09f3a03
Compare
How about type BaseException = PyBaseException; ? |
sounds good to me if it's marked deprecated |
Agreed marking the old functionality as deprecated. I'll try to finish off this PR at the weekend. |
This prototype implements use of Py<BaseException> as the instance to use for exception instances. These instances integrate reasonably well with the Rust’s standard error mechanisms by implementing the `Display` and `Error` traits. These error types can also be stored into e.g. `failure::Fail`s or other error types as a cause of some greater error.
09f3a03
to
daa13cf
Compare
I've updated this PR and rebased. I was originally intending to write more documentation as part of this PR, but now as I've been thinking about related designs such as |
9ba557d
to
4ed9748
Compare
This is a rework of pyo3's exception types to be more in line with the rest of the Python native types.
I introduce new exception types
PyException
,PyRuntimeError
etc. These must be accessed through eitherPy<PyBaseException>
,Py<PyRuntimeError>
or gil-scoped references&PyBaseException
,&PyRuntimeError
, just like other native types.To minimise breakage the old types
Exception
,RuntimeError
continue to exist and behave as they did before, but I mark them deprecated with a suggestion to use the new types.I think this is an important first step of #295 - we should then be able to make something very similar to
#[pyclass]
for exceptions. It should also enable #682 to be done relatively cleanly by building off these implementations.I based this PR on the work of #686, which I think can now be closed. As well as
Py<PyBaseException>
, I was able to implementstd::error::Error
forPy<T>
and&T
for all the error typesT
.This PR will introduce a couple of minor breaking changes, but I think it's worth it:
PyBorrowError
andPyBorrowMutError
no longer have dedicated Python types and just raiseRuntimeError
in Python.I could undo this change, however the
try_borrow()
would have to return&PyBorrowError
and we'll take a little performance hit.socket::herror
are now only accessible as native types; existing code using these will break slightly.If you like this, I'll press ahead with documentation.
TODO:
DocumentationEDIT: I'm going to write docs after some follow-up PRs, when it's easier to see what the final result looks like.