Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

AsPyRef is stripped down, not in changelog #738

Closed
birkenfeld opened this issue Jan 18, 2020 · 8 comments
Closed

AsPyRef is stripped down, not in changelog #738

birkenfeld opened this issue Jan 18, 2020 · 8 comments
Milestone

Comments

@birkenfeld
Copy link
Member

The AsPyRef trait was stripped down considerably; methods with, with_mut, into_py, into_mut_py are gone.

The changelog should mention how to rewrite code using them, or if removal was an oversight they should be reinstated.

@kngwyu
Copy link
Member

kngwyu commented Jan 19, 2020

Thank you.
Now I'm not sure why they exist so need to check them.
But anyway I will fix it until the non-alpha release.

@kngwyu kngwyu modified the milestone: 0.9.0 Jan 19, 2020
@birkenfeld
Copy link
Member Author

I was using them to access instances of a Rust object that were behind a Py<T> pointer.

If there is better or newer way, let me know :)

@birkenfeld
Copy link
Member Author

Any news on this?

@davidhewitt
Copy link
Member

davidhewitt commented Jan 28, 2020

There's a soundness problem; because Py<T> is a shared pointer, we need to be careful about getting &mut T from a Py<T>.

I think we really need to have RefCell-like semantics, where Py<T> will have .borrow(), .borrow_mut(), .try_borrow() and .try_borrow_mut() methods.

@kngwyu
Copy link
Member

kngwyu commented Jan 29, 2020

Just a reference for readers: https://docs.rs/pyo3/0.8.5/pyo3/trait.AsPyRef.html
@birkenfeld
I'm OK to retrieve with and with_mut. Are they sufficient?
into_py has a confusing name and I think it should be under another trait.

@davidhewitt
Py<T> can handle all Python pointers(including PyDict or so) and I'd rather enhance PyClassShell in that direction.

@birkenfeld
Copy link
Member Author

@davidhewitt you're right; this cannot be allowed like it was. A RefCell like functionality with runtime checking would be very nice.

@kngwyu with is probably also served by as_ref? with_mut needs a safer alternative, "somehow" :)

@kngwyu
Copy link
Member

kngwyu commented Mar 2, 2020

Now AsPyRef::as_ref is changed to return &PyCell.
For PyCell, please see the guide.

@kngwyu kngwyu closed this as completed Mar 2, 2020
@birkenfeld
Copy link
Member Author

Great, thanks!

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants