3 ms·
Do you mean like mypy and optional type hints or something different, enforceable like Typescript?
by daniel-s 2y ago
Do you mean like mypy and optional type hints or something different, enforceable like Typescript?
- fastball 2y agoI wouldn't really say Typescript is enforceable, given that the types aren't actually considered at runtime.
- pjmlp 2y agoIn fact, people should see Typescript as a linter / bundler tool than a programming language by itself, ignoring the design mistakes of how enums and namespaces came to be.
- pyrale 2y agoThat is the case for most typesystem considered safe, save for introspection use cases. For instance, haskell, a language with strong type guarantees, does erase types for runtime.
- School-Cotton 2y agoAlmost no languages have types considered at runtime.
- guappa 2y agoWell python does, after the famous PEP to pack all types into strings got parked (probably forever). There's packages to typecheck at runtime, even to check the parameters to a function.
- deleted 2y ago[deleted]
- grumbel 2y agoIt would be nice to have typing in the core language/interpreter, including runtime type errors, instead of this weird add-on approach. I constantly run into situation where the code is fine and mypy complains or the code is broken and mypy says it's fine. It all just feels like one gigantic fragile workaround instead of a proper type system that you can depend on.
- KaiserPro 2y agoIts not runtime enforceable though. Personally whilst I do provide type hints (I have a the linter setup to remind me) They are only really useful as a documentation tool. As they are not enforced at runtime, you can easily return bollocks and not know. I really like how c# does it, which is have strict typing on by default, but allowing you to turn it off for things where you're wanting to be loosey goosey. Not having to do a bunch of type checks on every operation would also speed up a bunch of things inside python However, that would make it a different language. perhaps python 4? (ducks)
- skeledrew 2y agoSee typeguard[0] for runtime type checking. I activate it only during testing, avoiding unnecessary overhead in prod. [0] https://pypi.org/project/typeguard/ https://pypi.org/project/typeguard/