|
|
|
|
|
by charliermarsh
1404 days ago
|
|
The "shapes of data" thing resonates a lot especially coming from TypeScript. The runtime validation stuff has been interesting to watch. Do you use Pydantic? It's very popular but I have a hard time getting over its willingness to cast / coerce implicitly (if I mark a field as an int, and pass in a str, I want an error -- is that weird of me?). |
|
> if I mark a field as an int, and pass in a str, I want an error -- is that weird of me
That is perfectly fine. And the question is why don't TypedDict, NamedTuple, dataclass raise during construction - since if they don't - we have to play it safe and do isinstance checking since we can't trust the field's types at runtime.
I suppose the idea the `typing` module [1] is to be unobtrusive: not to be involved in runtime checks.
What I want is something that does what pydantic does in standard library. I think it's a sensible request and would be indispensable for anyone wrangling data.
[1] https://docs.python.org/3/library/typing.html