May be what you mean is a static typing solution for Python whose syntax is a superset of Python syntax (which I don't think `erg` is), but isn't identical to Python's syntax( ie, it is a strict superset, which statically typed Python's syntax isn't). Typescript is exactly that for JS.
In that case, I agree with you that such an attempt would indeed be very interesting because it would allow for more aggressive exploration of ergonomic typing constructs while maintaining that any valid Python would be valid in that new language as well (just like TS).
However what I’m missing is having more advanced type constructs. For example mapped types, lookup types, etc [1].
That said, it seems like python devs keep adding features over time. For example a couple of years ago it wasn’t possible to specify which fields of a dictionary are required and not required (it required putting required fields in one TypedDict and then subclassing it into another one that had the non required ones with total=False), nor it was possible to “spread” a TypedDict to declare the kwarg types in a function.
[1]: https://www.typescriptlang.org/docs/handbook/release-notes/t...
The only thing you need to do is add appropriate type hints at function definitions and then run mypy in your build and CI and you got something that checks basically as strict as Java.
For those saying it’s optional so can’t be trusted, consider that compiling C++ with -Wall -Werror is also optional… adding it is simply part of standard project hygiene.
There's another comment making this claim elsewhere and I wonder if perhaps those assertions are coming from someone who doesn't write Java, or if my experience with mypy is just especially bad
I'll also point out that easily 90% of my heartburn with trying to typehint python in legacy projects is that python seems to encourage so much introspection and namespace trickery. It feels to me like the mypy audience is saying "well, there's a staticly typed language hiding in python so just don't use unsafe parts of the language and you'll be fine"
Pydantic requires inheritance and requires a modified mypy because it uses types its own way rather than the python way.
Oh, typedload is faster than pydantic, despite being pure python instead of an .so file.
I'm pretty sure that serde, the rust library that Pydantic uses, is faster than the JSON parser written in C in the python standard lib, so I'd be very surprised if your pure python validation library beat pydantic.
At the bottom there are instructions on how to run the benchmark locally.
So I modified the benchmarking code to include loading JSON[0], and your library still came out on top!
But, it turns out I was wrong about pydantic using serde under the hood. Pydantic version 2 will. And the maintainer aims for it to be about 10x faster [1] than version 1.
Nonetheless, this was definitely a surprise for me, and if I ever go back to using Python, I'll definitely check your library out!
I'm curious, why do you think pydantic took off and your library didn't? It looks like your library is both faster and easier to use to me.
[0] https://github.com/davidatsurge/typedload/pull/1/files?diff=...
Having them integrated could be advantageous to save memory and avoid loading the full json first. Like loading the objects directly to their final destination as the json gets parsed. But that would be kinda complicated.
I have absolutely no idea why mine isn't so used, but my model of GPL license + pay me to get LGPL license probably doesn't help. But is not a factor if used for internal stuff.
apischema is my second favourite one and it also doesn't have many users. However it came later so that's an easier explanation.
I recently tried a similar library called jsons. I wanted to benchmark it but it was too buggy to do a meaningful comparison. Of course it has 8x more downloads :D I guess the users either have very basic use cases or prefer working around the issues rather than trying a different library.
Finding a decent library is not easy. I'm trying to convince my coworkers to just drop and rewrite a bad golang library they are using and working around a lot.
I think something else that might help is if you make it more prominent (if it's visible right now at all, since I can't find it) the message that tells people, at least, "contact me to arrange a different license", or at best, a pricing model.
Well now in 2022… in 2018 there was nothing else. It was (and still is) the only option on python 3.5 AFAIK.
Thanks for the advice, I guess I can put something about that.