Skip to content

Commit 56b85cf

Browse files
committed
Extract the attribute names
1 parent 38f0a59 commit 56b85cf

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

pyo3-macros-backend/src/pyimpl.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use crate::{
99
pymethod::{self, is_proto_method},
1010
utils::get_pyo3_crate,
1111
};
12-
use proc_macro2::{Ident, TokenStream};
12+
use proc_macro2::{Ident, Literal, TokenStream};
1313
use pymethod::GeneratedPyMethod;
1414
use quote::{format_ident, quote};
1515
use syn::{parse::{Parse, ParseStream}, spanned::Spanned, Result, Type};
@@ -279,14 +279,17 @@ fn get_cfg_attributes(attrs: &[syn::Attribute]) -> Vec<&syn::Attribute> {
279279
}
280280

281281
fn generate_impl_info(cls: &Type, fields: Vec<Ident>) -> TokenStream {
282-
println!("Generating impl {:?}", cls);
283-
284282
let ident_prefix = generate_unique_ident(cls, None);
285283
let fields_info = format_ident!("{}_fields_info", ident_prefix);
286284

285+
let field_size = Literal::usize_suffixed(fields.len());
286+
287+
let fields = fields.iter()
288+
.map(|field| quote!(&#field));
289+
287290
quote! {
288-
const #fields_info: [&'static pyo3::interface::FieldInfo; 0] = [
289-
//TODO
291+
const #fields_info: [&'static pyo3::interface::FieldInfo; #field_size] = [
292+
#(#fields),*
290293
];
291294

292295
impl pyo3::interface::GetClassFields for #cls {

0 commit comments

Comments
 (0)