4 ms·
Author here: This specific example is a perfect case of the thing the post calls out! API boundaries are one of the most important places where we need to maint
by chriskrycho 3y ago
Author here: This specific example is a perfect case of the thing the post calls out! API boundaries are one of the most important places where we need to maintain invariants about our code base, one of the most important places that it is important not to have to worry about “keeping things in sync” as you say.
In the TypeScript world, there are a number of libraries that can handle creating types from deserialization logic: Zod [1], Superstruct [2], Typebox [3], etc. – and Typebox specifically does what you are looking to do with MyPy. I do not know the Python ecosystem at all anymore (it has been a decade!) but I would be surprised if nothing like that exists. If it does, there is a good chance it is associated with the functional programming enthusiast corner of the Python community, so you might look there!
[1]: https://github.com/colinhacks/zod https://github.com/colinhacks/zod
[2]: https://github.com/ianstormtaylor/superstruct https://github.com/ianstormtaylor/superstruct
[3]: https://github.com/sinclairzx81/typebox https://github.com/sinclairzx81/typebox
- eternityforest 3y agoThat is so cool! Typescript has some of the best ecosystem support out there. Python definitely does have tools like that, but many haven't been touched in a few years, and Python code sadly has a shelf life, although it seems to slowly be stabilizing.