diff --git a/derive/src/pyclass.rs b/derive/src/pyclass.rs index d8218b606..2dbccbf5d 100644 --- a/derive/src/pyclass.rs +++ b/derive/src/pyclass.rs @@ -686,18 +686,27 @@ fn extract_impl_attrs(attr: AttributeArgs) -> std::result::Result { if path_eq(&path, "with") { for meta in nested { - match meta { - NestedMeta::Meta(Meta::Path(path)) => { - withs.push(quote! { - ::__extend_py_class(ctx, class); - }); - with_slots.push(quote! { - ::__extend_slots(slots); - }); - } + let path = match meta { + NestedMeta::Meta(Meta::Path(path)) => path, meta => { bail_span!(meta, "#[pyimpl(with(...))] arguments should be paths") } + }; + if path_eq(&path, "PyRef") { + // special handling for PyRef + withs.push(quote! { + PyRef::::impl_extend_class(ctx, class); + }); + with_slots.push(quote! { + PyRef::::extend_slots(slots); + }); + } else { + withs.push(quote! { + ::__extend_py_class(ctx, class); + }); + with_slots.push(quote! { + ::__extend_slots(slots); + }); } } } else if path_eq(&path, "flags") {