Conversation
One thing that I would like to state explicitly to make sure that know everyone's assumptions: In my personal experience writing application-level code using PyO3, I have rarely interacted directly with native types like IMO, this implies that even if there is churn in their interfaces, it does not affect the majority of application-level code. But rather library and performance-critical code, the owners of which should be in a good position to fix that churn. (Of course, the still won't like us for making them do those changes. But the performance gains of removing the pool should be pretty persuasive to that crowd.) |
| /// Used by `PyList::iter()`. | ||
| pub struct PyListIterator<'a> { | ||
| list: &'a PyList, | ||
| pub struct PyListIterator<'py> { |
There was a problem hiding this comment.
Since this is not a #[pyclass], wouldn't the double indirection &'a PyList<'py> be closer to the usual Rust pattern for iterators borrowing the container? I think the iterator could still yield PyAny<'py> items though?
|
Closing in favour of #3361 |
This is a branch to continue the conversation from #3205 (comment)
It adds an (internal for now)
PyAnyOwned<'py>, which could eventually becomePyAny<'py>, and attempts to gauge fallout by replacing&'py PyListwithPyList<'py>implemented on top ofPyAnyOwned<'py>.Because of the scale of the churn, I think it's more realistic to implement migration of each type in individual PRs. I think a single branch and PR to rebuild the entirety of PyO3 would be unreviewable. Probably
&PyAnyneeds to be migrated first, although I want us to understand what changes look like for the core collection types (list, dict, tuple) before we commit to this road for definite.Doesn't compile yet because a lot of the conversion traits aren't implemented properly for
PyList<'py>. I might try to refine further later if we think this is worth pursuing.Already we see the following migration efforts:
from_owned_ptrmethods etc.PyList<'py>has interesting consequences foris_instanceand similar generic methods.x.is_instance_of::<PyList<'_>>()x.downcast::<PyList<'_>>()Of these, I think only the fourth bullet needs further consideration. If users don't have the
elided_lifetimes_in_pathslint enabled, then I believe they can continue writingx.is_instance_of<PyList>()without the lifetime. However, the papercut is still notable. I think this would just have to be noted as part of syntactical drawbacks which we could describe as things which would go away ifarbitrary_self_typesstabilised (any PyO3 migrated to it).