Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python Typeshare improvements #217

Open
5 tasks
hculea opened this issue Dec 5, 2024 · 0 comments
Open
5 tasks

Python Typeshare improvements #217

hculea opened this issue Dec 5, 2024 · 0 comments

Comments

@hculea
Copy link
Member

hculea commented Dec 5, 2024

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: conint from Pydantic (and other constrained types) can be used for tighter validation. For example, if the Rust type is u8, then we can leverage conint to bound the number from 0 to 255. Currently, this validation relies on the Rust deserializer.

  • Generics are not yet supported: struct and enum with generic parameters are not supported. For example, the test case can_generate_generic_enum is not enabled for Python as it is not supported. This can be achieved using TypeVar of 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 test can_override_types for 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_types function. See suggestion

Originally posted by @CheatCod in #169 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant