-
Notifications
You must be signed in to change notification settings - Fork 791
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix index error in parameter conversion codes #631
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -394,10 +394,8 @@ pub(crate) fn impl_wrap_setter( | |
|
||
/// This function abstracts away some copied code and can propably be simplified itself | ||
pub fn get_arg_names(spec: &FnSpec) -> Vec<syn::Ident> { | ||
spec.args | ||
.iter() | ||
.enumerate() | ||
.map(|(pos, _)| syn::Ident::new(&format!("arg{}", pos), Span::call_site())) | ||
(0..spec.args.len()) | ||
.map(|pos| syn::Ident::new(&format!("arg{}", pos), Span::call_site())) | ||
.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 option_pos = 0; | ||
|
@@ -461,15 +455,15 @@ pub fn impl_arg_params(spec: &FnSpec<'_>, body: TokenStream) -> TokenStream { | |
|
||
let accept_args = bool_to_ident(spec.accept_args()); | ||
let accept_kwargs = bool_to_ident(spec.accept_kwargs()); | ||
|
||
let num_normal_params = params.len(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is just refactoring, too. |
||
// create array of arguments, and then parse | ||
quote! { | ||
use pyo3::ObjectProtocol; | ||
const PARAMS: &'static [pyo3::derive_utils::ParamDescription] = &[ | ||
#(#params),* | ||
]; | ||
|
||
let mut output = [#(#placeholders),*]; | ||
let mut output = [None; #num_normal_params]; | ||
let mut _args = _args; | ||
let mut _kwargs = _kwargs; | ||
|
||
|
@@ -507,21 +501,22 @@ fn impl_arg_param( | |
let #arg_name = _py; | ||
}; | ||
} | ||
let arg_value = quote!(output[#option_pos]); | ||
*option_pos += 1; | ||
|
||
let ty = arg.ty; | ||
let name = arg.name; | ||
|
||
if spec.is_args(&name) { | ||
quote! { | ||
return quote! { | ||
let #arg_name = <#ty as pyo3::FromPyObject>::extract(_args.as_ref())?; | ||
} | ||
}; | ||
} else if spec.is_kwargs(&name) { | ||
quote! { | ||
return quote! { | ||
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) { | ||
if d.to_string() == "None" { | ||
quote! { None } | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just refactoring, not related to the core of this PR.