Merge pull request #631 from kngwyu/output-fix
Fix index error in parameter conversion codes
This commit is contained in:
commit
2713977fff
|
@ -394,10 +394,8 @@ pub(crate) fn impl_wrap_setter(
|
||||||
|
|
||||||
/// This function abstracts away some copied code and can propably be simplified itself
|
/// This function abstracts away some copied code and can propably be simplified itself
|
||||||
pub fn get_arg_names(spec: &FnSpec) -> Vec<syn::Ident> {
|
pub fn get_arg_names(spec: &FnSpec) -> Vec<syn::Ident> {
|
||||||
spec.args
|
(0..spec.args.len())
|
||||||
.iter()
|
.map(|pos| syn::Ident::new(&format!("arg{}", pos), Span::call_site()))
|
||||||
.enumerate()
|
|
||||||
.map(|(pos, _)| syn::Ident::new(&format!("arg{}", pos), Span::call_site()))
|
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -448,10 +446,6 @@ pub fn impl_arg_params(spec: &FnSpec<'_>, body: TokenStream) -> TokenStream {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
let placeholders: Vec<syn::Ident> = params
|
|
||||||
.iter()
|
|
||||||
.map(|_| syn::Ident::new("None", Span::call_site()))
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
let mut param_conversion = Vec::new();
|
let mut param_conversion = Vec::new();
|
||||||
let mut option_pos = 0;
|
let mut option_pos = 0;
|
||||||
|
@ -461,7 +455,7 @@ pub fn impl_arg_params(spec: &FnSpec<'_>, body: TokenStream) -> TokenStream {
|
||||||
|
|
||||||
let accept_args = bool_to_ident(spec.accept_args());
|
let accept_args = bool_to_ident(spec.accept_args());
|
||||||
let accept_kwargs = bool_to_ident(spec.accept_kwargs());
|
let accept_kwargs = bool_to_ident(spec.accept_kwargs());
|
||||||
|
let num_normal_params = params.len();
|
||||||
// create array of arguments, and then parse
|
// create array of arguments, and then parse
|
||||||
quote! {
|
quote! {
|
||||||
use pyo3::ObjectProtocol;
|
use pyo3::ObjectProtocol;
|
||||||
|
@ -469,7 +463,7 @@ pub fn impl_arg_params(spec: &FnSpec<'_>, body: TokenStream) -> TokenStream {
|
||||||
#(#params),*
|
#(#params),*
|
||||||
];
|
];
|
||||||
|
|
||||||
let mut output = [#(#placeholders),*];
|
let mut output = [None; #num_normal_params];
|
||||||
let mut _args = _args;
|
let mut _args = _args;
|
||||||
let mut _kwargs = _kwargs;
|
let mut _kwargs = _kwargs;
|
||||||
|
|
||||||
|
@ -507,21 +501,22 @@ fn impl_arg_param(
|
||||||
let #arg_name = _py;
|
let #arg_name = _py;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
let arg_value = quote!(output[#option_pos]);
|
|
||||||
*option_pos += 1;
|
|
||||||
|
|
||||||
let ty = arg.ty;
|
let ty = arg.ty;
|
||||||
let name = arg.name;
|
let name = arg.name;
|
||||||
|
|
||||||
if spec.is_args(&name) {
|
if spec.is_args(&name) {
|
||||||
quote! {
|
return quote! {
|
||||||
let #arg_name = <#ty as pyo3::FromPyObject>::extract(_args.as_ref())?;
|
let #arg_name = <#ty as pyo3::FromPyObject>::extract(_args.as_ref())?;
|
||||||
}
|
};
|
||||||
} else if spec.is_kwargs(&name) {
|
} else if spec.is_kwargs(&name) {
|
||||||
quote! {
|
return quote! {
|
||||||
let #arg_name = _kwargs;
|
let #arg_name = _kwargs;
|
||||||
}
|
};
|
||||||
} else if arg.optional.is_some() {
|
}
|
||||||
|
let arg_value = quote!(output[#option_pos]);
|
||||||
|
*option_pos += 1;
|
||||||
|
if arg.optional.is_some() {
|
||||||
let default = if let Some(d) = spec.default_value(name) {
|
let default = if let Some(d) = spec.default_value(name) {
|
||||||
if d.to_string() == "None" {
|
if d.to_string() == "None" {
|
||||||
quote! { None }
|
quote! { None }
|
||||||
|
|
Loading…
Reference in New Issue