Skip to content

Commit

Permalink
Python Generator now creates types = None in classes for all optional…
Browse files Browse the repository at this point in the history
… types

This was previously breaking literal? types
  • Loading branch information
hellovai committed Nov 12, 2024
1 parent 8b51b6e commit e467f07
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 120 deletions.
10 changes: 5 additions & 5 deletions engine/language_client_codegen/src/python/generate_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ impl<'ir> From<ClassWalker<'ir>> for PythonClass<'ir> {
Cow::Borrowed(f.elem.name.as_str()),
add_default_value(
&f.elem.r#type.elem,
&f.elem.r#type.elem.to_type_ref(&c.db),
f.elem.r#type.elem.to_type_ref(&c.db),
),
)
})
Expand Down Expand Up @@ -151,7 +151,7 @@ impl<'ir> From<ClassWalker<'ir>> for PartialPythonClass<'ir> {
f.elem.name.as_str(),
add_default_value(
&f.elem.r#type.elem,
&f.elem.r#type.elem.to_partial_type_ref(&c.db, false),
f.elem.r#type.elem.to_partial_type_ref(&c.db, false),
),
)
})
Expand All @@ -160,11 +160,11 @@ impl<'ir> From<ClassWalker<'ir>> for PartialPythonClass<'ir> {
}
}

pub fn add_default_value(node: &FieldType, type_str: &String) -> String {
if type_str.starts_with("Optional[") {
pub fn add_default_value(node: &FieldType, type_str: String) -> String {
if node.is_optional() {
return format!("{} = None", type_str);
} else {
return type_str.clone();
return type_str;
}
}

Expand Down
Loading

0 comments on commit e467f07

Please sign in to comment.