@@ -54,6 +54,7 @@ pub struct StructBindGenerator {
5454 has_complex_pack : bool ,
5555 pub is_frozen : bool ,
5656 is_no_set : bool ,
57+ pub default_override : Option < ( & ' static str , & ' static str ) > ,
5758}
5859
5960macro_rules! write_str {
@@ -103,6 +104,17 @@ impl StructBindGenerator {
103104 file_contents. push ( Cow :: Borrowed ( "use pyo3::{prelude::*, types::*};" ) ) ;
104105 file_contents. push ( Cow :: Borrowed ( "" ) ) ;
105106
107+ let default_override =
108+ PythonBindType :: DEFAULT_OVERRIDES
109+ . iter ( )
110+ . find_map ( |& ( name, field, value) | {
111+ if name == struct_name. as_str ( ) {
112+ Some ( ( field, value) )
113+ } else {
114+ None
115+ }
116+ } ) ;
117+
106118 Some ( Self {
107119 filename,
108120 struct_name,
@@ -113,6 +125,7 @@ impl StructBindGenerator {
113125 has_complex_pack,
114126 is_frozen,
115127 is_no_set,
128+ default_override,
116129 } )
117130 }
118131
@@ -297,6 +310,13 @@ impl StructBindGenerator {
297310 for variable_info in & self . types {
298311 let variable_name = variable_info. name . as_str ( ) ;
299312
313+ if let Some ( ( field, value) ) = self . default_override {
314+ if field == variable_name {
315+ signature_parts. push ( format ! ( "{variable_name}={value}" ) ) ;
316+ continue ;
317+ }
318+ }
319+
300320 let sig_part = match & variable_info. rust_type {
301321 RustType :: Option ( _, _) => {
302322 if variable_info. is_special_base . is_some ( ) {
@@ -955,6 +975,13 @@ impl Generator for StructBindGenerator {
955975 for variable_info in & self . types {
956976 let variable_name = variable_info. name . as_str ( ) ;
957977
978+ if let Some ( ( field, value) ) = self . default_override {
979+ if field == variable_name {
980+ write_fmt ! ( self , " {variable_name}: {value}," ) ;
981+ continue ;
982+ }
983+ }
984+
958985 let end = match & variable_info. rust_type {
959986 RustType :: Vec ( InnerVecType :: U8 ) => Cow :: Borrowed ( "PyBytes::new(py, &[]).unbind()" ) ,
960987 RustType :: Vec ( InnerVecType :: Custom ( _) ) => {
0 commit comments