3 ms·
NewType and TypeGuard are pretty close to a trait. I really want this approach to be awesome but it’s actually ironically seemingly more work to write python li
by bionhoward 3y ago
NewType and TypeGuard are pretty close to a trait. I really want this approach to be awesome but it’s actually ironically seemingly more work to write python like rust than to just write rust. I say this because if you write python like rust then you have to re-invent and unit test and e2e test a bunch of stuff you get for free in rust.
I do think Immutables.Map + NewType + TypeGuard is enough for some awesome category theory stuff, but it’s a bit harder with Pydantic if you want to handle nested stuff (I guess I just need to make more data classes) and then another issue is you have to write custom code to check if a thing implements a given trait. Then you have to use that.
Making sure all of that basic stuff you get for free in rust works correctly in your Python implementation is a bit of work! Worth it? unclear, still testing, I do love me some duck typing!