Add AsRefSource to PyNativeType.#3653
Conversation
adamreichold
left a comment
There was a problem hiding this comment.
I don't think we should hold off on the quality-of-life improvements for internal work as it makes this faster.
I am currently not seeing a downside besides a general unease with more coupling within our already complex trait landscape. Is there anything in particular that one should be aware of?
|
Thanks; yes this makes migration work nicer for sure. I think the only downside is that manual implementors of In the longer term, I think we can throw away the whole |
|
(it should be noted that I don't expect there to be downstream manual implementors of |
This adds an associated type
AsRefSourcetoPyNativeType.This allows type inference in the reverse direction
&T -> Py<T>, which is particularly useful for&PyCell<T> -> Py2<T>. It also helps for forwarding our gil-ref methods to the new traits, e.g. by solving the inference problem in #3652Really this is most helpful when we're in a transition phase where users might be using
Py2::borrowed_from_gil_refthemselves. So I'm also happy to decide that we don't merge this until we're ready to releasePy2as a whole, and for now we just continue to add type annotations while we're landing the groundwork internally.