Skip to content

Commit

Permalink
added None default to Optional python type
Browse files Browse the repository at this point in the history
  • Loading branch information
amandayu1 committed Aug 22, 2024
1 parent fde8907 commit dce626a
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions core/src/language/python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ 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[{}] = None", python_type);
self.module
.add_import("typing".to_string(), "Optional".to_string());
}
Expand All @@ -678,7 +678,7 @@ impl Python {
self.module
.add_import("pydantic".to_string(), "Field".to_string());
format!(
"Annotated[{}, Field(alias=\"{}\")]",
"Annotated[{}, Field(alias=\"{}\")] = None",
python_type, field.id.renamed
)
}
Expand All @@ -688,7 +688,7 @@ impl Python {
w,
" {}: {} = {}",
python_field_name, python_type, default,
)?,
)?,
None => writeln!(w, " {}: {}", python_field_name, python_type)?,
}

Expand Down

0 comments on commit dce626a

Please sign in to comment.