-
Notifications
You must be signed in to change notification settings - Fork 837
Use Arbitrary Self Types instead of Py<Type>Methods traits #4885
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
base: main
Are you sure you want to change the base?
Conversation
4076c62
to
42045ca
Compare
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 very much for running with this! I haven't managed to read in detail, can you summarise how it feels to use? I see there's a fair bit of path syntax change, that's unexpected to me.
Do you think we should be proceeding down this road? Does it seem like it's something fundamental with our design that's wrong? Or something in the self types feature which we should flag upstream before it stabilizes?
Currently I think there's some rough edges. The existing
I'm currently experimenting with some alternative designs to see what level of churn they cause. Once I've finished with those, I'll have a better idea. But unless these other designs work much better, I think we'll need to flag to upstream. |
Arbitrary self types conflicts with the `Deref` implementation for `Bound<'py, T> where T: DerefToPyAny`. This commit replaces that implementation with a blanket implementation of `PyAnyMethods` instead. Unfortunately, this greatly increases the verbosity of using `Py_Methods` when multiple traits match. It also requires many more calls to `as_any()` or `into_any()`.
This largely replaces the need for `Py<Type>Methods` traits, since these methods can now be implemented directly on the type.
42045ca
to
8ac0215
Compare
I now think this is very workable. We'll need to decide how best to handle the loss of |
002cce5
to
3f8b496
Compare
3f8b496
to
c44c9db
Compare
For #4869.
I removed the
Deref
implementation forBound<'py, T>
because it conflicts with any implementation ofstd::ops::Receiver
we need to use Arbitrary Self Types. For example:I also added an implementation of
PyAnyMethods
forBound<'py, T>
to compensate for the removal ofDeref
. To get this working, I dropped the requirement thatPyAnyMethods
can only be implemented for sealed types. An alternative approach I think would be to just removeDeref
and require.as_any()
or.into_any()
calls in more places.After all of this,
clippy
passes on nightly on my machine (with the exception of one lint, which I think is unrelated to this PR). I can also run much of the test suite, but get an error in#[pyclass]
which I currently don't understand:I'm confident this is coming from
pyo3/pyo3-macros-backend/src/pyclass.rs
Line 1834 in 29c64d8
.as_type_ptr
method shouldn't be found, since it's implemented inpyo3/src/types/typeobject.rs
Lines 51 to 54 in 29c64d8