Skip to content

Commit

Permalink
Fix return type for __init__() bindings
Browse files Browse the repository at this point in the history
Signed-off-by: Andrej Orsula <[email protected]>
  • Loading branch information
AndrejOrsula committed Jan 26, 2024
1 parent 2acac48 commit 0b22727
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions pyo3_bindgen_engine/src/bindgen/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,6 @@ pub fn bind_function<S: ::std::hash::BuildHasher + Default>(
.into_rs_borrowed(module_name, all_types)
})
.collect_vec();
let return_annotation =
Type::try_from(return_annotation.unwrap_or(pynone))?.into_rs_owned(module_name, all_types);

let mut doc = function.getattr("__doc__")?.to_string();
if doc == "None" {
Expand Down Expand Up @@ -228,6 +226,14 @@ pub fn bind_function<S: ::std::hash::BuildHasher + Default>(

let is_init_fn = function_name == "__init__";

let return_annotation = if is_init_fn && method_of_class.is_some() {
quote::quote! {
&'py Self
}
} else {
Type::try_from(return_annotation.unwrap_or(pynone))?.into_rs_owned(module_name, all_types)
};

let call_method = match (is_init_fn, has_positional_args, has_kwargs) {
(true, _, true) => {
quote::quote! {
Expand Down

0 comments on commit 0b22727

Please sign in to comment.