From 5c88f1942ce374939b508dc02944c56a7500cf5d Mon Sep 17 00:00:00 2001 From: Amanda Yu Date: Tue, 20 Aug 2024 16:55:49 -0400 Subject: [PATCH 1/3] added None default to Optional python type --- core/src/language/python.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/language/python.rs b/core/src/language/python.rs index bf982783..d0fe1ba3 100644 --- a/core/src/language/python.rs +++ b/core/src/language/python.rs @@ -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 ) } From 66ef407c2822979e19a6477c74f92a8cb44fc3e8 Mon Sep 17 00:00:00 2001 From: Amanda Yu Date: Thu, 22 Aug 2024 13:05:44 -0400 Subject: [PATCH 2/3] added None to Optional field --- core/src/language/python.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/language/python.rs b/core/src/language/python.rs index d0fe1ba3..792494c8 100644 --- a/core/src/language/python.rs +++ b/core/src/language/python.rs @@ -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()); } @@ -688,7 +688,7 @@ impl Python { w, " {}: {} = {}", python_field_name, python_type, default, - )?, + )?, None => writeln!(w, " {}: {}", python_field_name, python_type)?, } From ba24efff8a1fdfa6bdf84b3994622ffcdaed2e19 Mon Sep 17 00:00:00 2001 From: Amanda Yu Date: Thu, 22 Aug 2024 13:05:44 -0400 Subject: [PATCH 3/3] added None to Optional field --- core/src/language/python.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/language/python.rs b/core/src/language/python.rs index d0fe1ba3..792494c8 100644 --- a/core/src/language/python.rs +++ b/core/src/language/python.rs @@ -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()); } @@ -688,7 +688,7 @@ impl Python { w, " {}: {} = {}", python_field_name, python_type, default, - )?, + )?, None => writeln!(w, " {}: {}", python_field_name, python_type)?, }