Skip to content

Commit 191298d

Browse files
committed
Support field type overrides in Python
1 parent 7c8c3f4 commit 191298d

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

core/src/language/python.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use crate::language::SupportedLanguage;
12
use crate::parser::ParsedData;
23
use crate::rust_types::{RustEnumShared, RustItem, RustType, RustTypeFormatError, SpecialRustType};
34
use crate::topsort::topsort;
@@ -448,9 +449,12 @@ impl Python {
448449
let is_optional = field.ty.is_optional() || field.has_default;
449450
// currently, if a field has a serde default value, it must be an Option
450451
let not_optional_but_default = !field.ty.is_optional() && field.has_default;
451-
let python_type = self
452-
.format_type(&field.ty, generic_types)
453-
.map_err(std::io::Error::other)?;
452+
let python_type: String = match field.type_override(SupportedLanguage::Python) {
453+
Some(type_override) => type_override.to_owned(),
454+
None => self
455+
.format_type(&field.ty, generic_types)
456+
.map_err(std::io::Error::other)?,
457+
};
454458
let python_field_name = python_property_aware_rename(&field.id.original);
455459
let is_aliased = python_field_name != field.id.renamed;
456460
let custom_translations = json_translation_for_type(&python_type);

0 commit comments

Comments
 (0)