deprecate super class initialization from tuples#5741
deprecate super class initialization from tuples#5741
Conversation
43a7cdd to
eeb230c
Compare
davidhewitt
left a comment
There was a problem hiding this comment.
Thanks, this looks good to me. Some thoughts:
- We should probably touch up the docs and guide to make it easier for users to understand how to use
PyClassInitializer. - Should we be figuring out how to pass arguments to super
__new__before asking users to migrate existing code? I am not entirely sure we won't have to change thePyClassInitializerAPI to make that possible, and it might be unfortunate if we push users to use this API just for us to change it again.
guide/src/class.md
Outdated
There was a problem hiding this comment.
This doc needs updating, probably should just mention PyClassInitializer here.
guide/src/class.md
Outdated
Good question. I think this depends on how we want that API to look like. The simple solution would probably be to add something like For example something like this: impl<T: PyClass> PyClassInitializer<T> {
...
pub fn add_args(mut self, args: Bound<'_, PyTuple>) -> Self
where
T::BaseType: PyClassBaseType<Initializer = PyNativeTypeInitializer<T::BaseType>>,
{
self.args = Some(args.unbind());
self
}
pub fn add_kwargs(mut self, kwargs: Bound<'_, PyDict>) -> Self
where
T::BaseType: PyClassBaseType<Initializer = PyNativeTypeInitializer<T::BaseType>>,
{
self.kwargs = Some(kwargs.unbind());
self
}
...
}And usage like this: #[pyclass(subclass, extends=PyDict)]
struct Foo {}
#[pyclass(extends=Foo)]
struct Bar;
#[pymethods]
impl Bar {
#[new]
fn new(py: Python<'_>) -> PyClassInitializer<Self> {
let args = todo!();
PyClassInitializer::from(Foo {}).add_args(args).add_subclass(Bar)
}
} |
eeb230c to
820716e
Compare
|
I think that API could certainly work, I also have a few scattered thoughts which might influence us:
|
|
I believe #4443 is touching on the same issue (albeit just for native supertypes). |
This deprecates the tuple syntax for super class initialization as per #5739 (review).
In
#[new]this will emit a deprecation warning when detected. As for theFrom<(S, B)> for PyClassInitializer<S>impl, I'm not sure we can do more that mentioning it in the changelog and migration guide.