Skip to content
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

Python Generator now creates types = None in classes for all optional types #1165

Open
wants to merge 1 commit into
base: canary
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change from &String to String in the add_default_value function signature is unnecessary and can lead to unnecessary cloning. Consider reverting to &String for efficiency.

Suggested change
pub fn add_default_value(node: &FieldType, type_str: String) -> String {
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
Loading