From 1f309322d7dac01c31af28ff6b6e17bbc219b8a5 Mon Sep 17 00:00:00 2001 From: Jeong YunWon Date: Fri, 25 Sep 2020 02:46:07 +0900 Subject: [PATCH] Allow #[pyimpl(with(PyRef))] --- derive/src/pyclass.rs | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) 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") {