-
Notifications
You must be signed in to change notification settings - Fork 99
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
Add Typeshare support for Python #169
base: main
Are you sure you want to change the base?
Add Typeshare support for Python #169
Conversation
Thanks to the prior work of @adriangb: 1Password#25
Doing some review, sorry for the delay. I'd like to ask for a high-level description in this MR for how this integration works, with especial focus on how structs are handled (in particular how the JSON <-> struct boundary is handled). |
f4540ab
to
85634d4
Compare
85634d4
to
48a8adb
Compare
fbfde61
to
5c88f19
Compare
c901b1b
to
9935aaf
Compare
* Add feature flag for Python TS * Fix length of arrays * Remove Available Languages and make it more scaleable * make languages mutable
* init * refactor functionality to its own method * remove serde * test signing * YOUR_COMMIT_MESSAGE * test signing * YOUR_COMMIT_MESSAGE * test signing * test signing * YOUR_COMMIT_MESSAGE * YOUR_COMMIT_MESSAGE * YOUR_COMMIT_MESSAGE * YOUR_COMMIT_MESSAGE * rewrite tests * fix generation * remove comma in types * remove inner * wip test * setup test and fix tests * fix * enable and fix more tests * add ctor for each variant class * extract to method * add support for ctor method for unit and tuple variants * fix formatting * apply omar's fixes * Add more snapshot tests and remove unused function * Add expected outputs for snapshot tests * Change unit enums to pass as content and fix some unneeded imports * fix config test * Add newline for EOF * Add snapshot test for serde default * make code more readable * fix single union, and rework to new pydantic standard * fix unit tests * remove useless tests * remove empty unit class generation, remove unit variant from union * update test --------- Co-authored-by: Omar Miraj <omar.miraj@agilebits.com>
Hey @Lucretiel, For the Python TS integration, we focused on incorporating Pydantic as our primary method for data validation and JSON serialization/deserialization. Some reasons on why I chose Active Support and Maintenance: The Pydantic package is well-supported and actively maintained, ensuring we can rely on its features and updates over time. Robust Data Validation: Pydantic provides a strong data validation framework that allows us to define and enforce data types and structures in Python. This guarantees that the data types, number of fields, and overall structure align with our defined schema. Seamless JSON Handling: The serialization and deserialization of JSON with Pydantic are incredibly smooth. It allows us to effortlessly convert our models to JSON while preserving their types and formatting, and it also validates incoming JSON data. This capability is something we currently utilize in our SDKs.(link to the SDKs doesn't work here lol) Also, while newer Python versions are increasingly adopting advanced type hinting and validation features, Pydantic enables us to maintain compatibility with older Python versions that may not support these new features. To serialize in
In here we have a
We can also add different arguments such as excluding fields or including only specific fields in the output and many more which can be found here:
For deserialization, we can deserialize according to the schema as follows:
This will ensure that the JSON received matches against the schema and if not throws a pretty bonus: Pydantic 2.x was written completely in Rust :) |
Forgot to mention but we currently do not support generics as we have yet to figure out on an ideal/idiomatic way to handle them in Python so we left it out of this PR. |
Thanks for the mention @MOmarMiraj 😄 That should be okay while Python support is still experimental (FWIW, Go doesn't support generics either) |
@Lucretiel does @MOmarMiraj 's comment above answer to your high-level description request? Otherwise, we're happy to provide more context on the choices that were made here. Thanks! |
…culea/typeshare into hculea/add-python-support-in-typeshare
This PR is adding initial support for Python in Typeshare (gated by a feature flag, like Go).
See @MOmarMiraj 's comment for a high-level description of the design considerations behind this work.
This was made possible thanks to the prior work of @adriangb: #25.