Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> trust that the static types are truthful

That's often a mistake even in typed languages like typescript. Satisfying a static type analyzer isn't enough. Real data is whatever it is going to be. If your types are meaningless at runtime, you can easily encounter type mismatches.

Static typing as implemented in typescript and python type hints is a tool for engineers instead of a tool for systems.



The types are usually ignored, but not entirely erased- Pydantic uses type hints to do validation at runtime, so if you construct a Pydantic object with invalid data it will throw an error, so eg

    foo=PydanticFoo(**request.json())
Will try and validate a json request against the implied schema provided by the type hints on PydanticFoo while constructing it and will throw if it fails.


You missed my point. If you validate input, then the static types are representative of runtime types


Ack, so I did :P




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: