Add IntoPyObject & FromPyObject for Arc<T>#4987
Add IntoPyObject & FromPyObject for Arc<T>#4987bschoenmaeckers wants to merge 2 commits intoPyO3:mainfrom
IntoPyObject & FromPyObject for Arc<T>#4987Conversation
6d0976c to
15b3e13
Compare
15b3e13 to
3220501
Compare
Icxolu
left a comment
There was a problem hiding this comment.
Interesting workaround. I wonder whether the additional type parameters have any impact on type inference. Did you perhaps tested/noticed anything in that regard? Maybe with the derive macro?
Also: Is it sufficiently clear that a roundtrip with Arc will not give the same Arc? Or should we document that somewhere?
I didn't experience any weird inference behaviour when writing the existing test. The new macro tests behaves fine so I think we are good there as well.
I am not sure if it needs explicit documentation, as all roundtrip conversions create new objects, why would this one differ? That said documentation doesn't hurt nobody. |
|
One alternative possibility here is that we change the I imagine mostly that would be |
I do not fully understand your second case. Can you give me a example of a class definition? |
I imagine something like #[pyclass]
struct MemoryView{
owner: Py<SomethingThatHasVecU8>,
ptr: *mut u8,
}Anyway, I share @Icxolu thoughts around roundtripping and ambiguity, and am inclined to not have this. If a user really wants a getter to an Arc field they can write a getter method and will be forced to consider the semantics they want. |
|
To follow up here - I was thinking that to allow |
|
|
Closes #4887.
This PR adds IntoPyObject and FromPyObject for Arc by forwarding the conversion to &T. Since we can’t access T, we work around the naming of associated types by adding extra type parameters. This fixes the conversion error when using #[pyclass(get)] with Arc fields.