6 ms·
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?
by charliermarsh 4y 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?).
- stevesimmons 4y agoYou can type it as StrictInt etc to stop this implicit type conversion. https://pydantic-docs.helpmanual.io/usage/types/#strict-types https://pydantic-docs.helpmanual.io/usage/types/#strict-type...
- tony 4y agoI haven't used pydantic yet. I'm conservative when adding (non-dev) dependencies since I am maintaining library packages. For other projects, it's a possibility. > 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 https://docs.python.org/3/library/typing.html