Re:Should You Use Upper Bound Version Constraints (In Python)?
by int_19h on Wednesday April 17, 2024 @01:40AM
(#40060874)
> A static language would be far less ergonomic to use for the typical prototyping and explorative programming done in Python.
A static language without type inference, sure. But that's not the only option.
OCaml, for example, will infer object types for you based on what methods are called with what kinds of arguments inside the body.
Re:Should You Use Upper Bound Version Constraints (In Python)?
by flakes on Wednesday April 17, 2024 @03:09AM
(#40061440)
> They are not checked at runtime at all. Type declarations are only used for static analyzing tools and not by the runtime.
This is the common usecase, but types certainly are used at runtime by many libraries. Frameworks like FastAPI use the type annotations to declare dependency injection which is resolved during application startup. In other cases like Pydantic, they are used to determine marshalling/unmarshalling strategies.
They are not checked at runtime at all. Type declarations are only used for static analyzing tools and not by the runtime.
So types are checked BEFORE runtime by the tooling just like they would be in TypeScript or any other language that offers gradual typing.
Yes, the dynamic nature of Python does make type safety and certain performance optimizations very difficult but then again it is the dynamic nature that allows for the high productivity of the language. A static language would be far less ergonomic to use for the typical prototyping and explorative programming done in Python.