Skip to content

Commit

Permalink
Fix logic of placing default to None
Browse files Browse the repository at this point in the history
  • Loading branch information
MOmarMiraj committed Jul 31, 2024
1 parent f0f01f2 commit f4540ab
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions core/src/language/python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,15 +277,9 @@ impl Language for Python {
.add_import("typing".to_string(), "List".to_string());
Ok(format!("List[{}]", self.format_type(rtype, generic_types)?))
}
//= Field(default=None)
// We add optionality above the type formatting level
SpecialRustType::Option(rtype) => {
self.module
.add_import("pydantic".to_owned(), "Field".to_owned());
Ok(format!(
"{} = Field(default=None)",
self.format_type(rtype, generic_types)?
))
}
SpecialRustType::Option(rtype) => self.format_type(rtype, generic_types),
SpecialRustType::HashMap(rtype1, rtype2) => {
self.module
.add_import("typing".to_string(), "Dict".to_string());
Expand Down Expand Up @@ -666,9 +660,11 @@ impl Python {
.format_type(&field.ty, generic_types)
.map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e))?;
if field.ty.is_optional() || field.has_default {
python_type = format!("Optional[{}]", python_type);
python_type = format!("Optional[{}] = Field(default=None)", python_type);
self.module
.add_import("typing".to_string(), "Optional".to_string());
self.module
.add_import("pydantic".to_owned(), "Field".to_owned());
}
let mut default = None;
if field.has_default {
Expand Down

0 comments on commit f4540ab

Please sign in to comment.