-
Notifications
You must be signed in to change notification settings - Fork 784
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
feat: add #[pyo3(get, set)] for Cell #3014
Conversation
0bb59b1
to
4d1f156
Compare
src/conversion.rs
Outdated
} | ||
} | ||
|
||
impl<T: Clone + IntoPy<PyObject>> IntoPy<PyObject> for Box<T> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Clone
bound is not necessary IIUC, e.g.
impl<T: IntoPy<PyObject>> IntoPy<PyObject> for Box<T> {
fn into_py(self, py: Python<'_>) -> PyObject {
(*self).into_py(py)
}
}
src/conversion.rs
Outdated
} | ||
} | ||
|
||
// impl<'a, T: FromPyObject<'a>> FromPyObject<'a> for Box<T> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the coherence error is correct insofar Box<T>
is a "fundamental" type IIRC, i.e. downstream crates can impl PyClass for Box<T>
with the same coherence rules as if they implemented impl PyClass for T
.
I am not sure whether we can get around this without introducer said additional trait to decouple FromPyObject
's task to "produce a T
given a PyAny
" from the new (sealed) trait's "I consider this a transparent wrapper of its inner value get/set purposes", so maybe
trait PyPropertyWrapper<T>: Sealed {
fn set(val: T) -> Self;
fn get(&self) -> T;
}
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for letting me know about fundamental types, this explains the issue with Box
!
I think the Arc/Box impls are a bad idea. In all cases I've seen where people stumbled upon their lack of impls this would not do what people expect, for example if you have a binary tree like in #2839, then |
I also feel like |
I have to agree with the reservations about The thought is that for e.g. For |
Thanks everyone for your feedback! I didn't foresee the potentials flaws of implementing |
Agreed. I think the |
4d1f156
to
81c8ac1
Compare
62120be
to
504825a
Compare
504825a
to
a629e82
Compare
bors r+ |
Build succeeded: |
This fixes #2659.
The types for which
#[pyo3(get, set)]
should now work areCell
,Arc
andBox
.There is one issue regarding
Box
, the implementation ofFromPyObject
conflicts with another one. I could not find what the issue was, especially since the other implementations forArc
andCell
work as expected. The related code and test has been commented out for now. Maybe someone could help me fix this issue if I don't figure it out myself? There is also the possibility to remove the implementation forBox
of course.