-
Notifications
You must be signed in to change notification settings - Fork 120
Description
In #169 support for Python is being added in Typeshare. This enables the majority of Rust -> Python type translation use-cases leveraging Pydantic, a data validation library for Python.
This issue captures follow-up improvements for the Python typeshare implementation, that have been left out of scope for the first iteration.
-
Tighter type validation:
conintfrom Pydantic (and other constrained types) can be used for tighter validation. For example, if the Rust type is u8, then we can leverageconintto bound the number from 0 to 255. Currently, this validation relies on the Rust deserializer. -
Generics are not yet supported:
structandenumwith generic parameters are not supported. For example, the test casecan_generate_generic_enumis not enabled for Python as it is not supported. This can be achieved usingTypeVarof the typing library. -
Only support for adjacently tagged enums: Rust
enums must be adjacently tagged, like#[serde(tag = "t", content = "c")], other enum representations, such as internally, externally or untagged are not supported. This is a limitation for the entire Typeshare framework, which already throws parsing errors in the absence of adjacent enum tags. -
Type overriding is not supported: Type overriding with the
#[typeshare]macro is not supported. See the testcan_override_typesfor details. -
Multi-file support: Currently, all the Python types are written to a single file. @darrell-roberts has shared a potential solution to this here.
- part of this will be to remove the overriden
generate_typesfunction. See suggestion
- part of this will be to remove the overriden
Originally posted by @CheatCod in #169 (comment)