-
Notifications
You must be signed in to change notification settings - Fork 763
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
Py::new
might not need to return PyResult
#1081
Comments
It was interesting to note for pyclasses that |
Candidate for 0.12? |
Would be cool but I'm slightly concerned the limited API may affect the code paths here, so I think we should coordinate this with the abi3 work in 0.13. |
Further thinking on this subject is that perhaps Rust types which subclass Python types could be fallible to construct, so this issue probably shouldn't be implemented before #991. |
I think with #4041 we are now thinking that into-python conversions will likely be fallible in the future, and given the subclassing issue above I think the general conclusion is that this should stay fallible (as it currently is). |
At the moment
Py::new
returnsPyResult<Py<T>>
, though in discussion in #1074 (comment) we came to concensus that it can probably just returnPy<T>
. The only error situation which can occur is out-of-memory. Most other pyo3 constructors where this is the only error situation just panic on OOM. (This is the same in the Rust stdlib.)At the moment this fallibility comes down to
PyClassAlloc::new
returning nullptr on any error. And alsoPyClassAlloc::new
can allocate a subtype, which could run arbitrary code through the subtype'stp_alloc
.If
PyClassAlloc::new
was split into e.g.::new
and::new_subtype
, where::new
always allocatesSelf
, then we should be able to refactor code enough to change semantics ofPy::new
so that it panics on OOM.pyo3/src/pycell.rs
Lines 374 to 377 in f2ba3e6
The text was updated successfully, but these errors were encountered: