3 ms·
The only reason to consider type hints is for a performance increase and there wasn't any mention of that. What can you really expect from using type hints accu
by Heston 3y ago
The only reason to consider type hints is for a performance increase and there wasn't any mention of that. What can you really expect from using type hints accurately?
- gaganyaan 3y agoType hints are great when using FastAPI. Your inputs are automatically validated, and you get a /docs endpoint that tells people what to expect from your API. I'd say performance is far from the only reason to consider type hints.
- maleldil 3y agoSimilarly for Typer, which is literally "the FastAPI of CLIs"[1]. Handy to type your `main` parameters and have CLI argument parsing. For more complicated cases, it's a wrapper around Click. [1] https://typer.tiangolo.com/ https://typer.tiangolo.com/
- abdullahkhalids 3y ago> Compiler instructions > I don’t know how many people are doing this, but tools like mypyc will use type hints to compile Python code to something faster, like C extensions.
- dragonwriter 3y ago> The only reason to consider type hints is for a performance increase No, the reason to consider type hints is because it makes it easier to understand existing code and write new code that interacts with it correctly. Comprehensibility and correctness are more important than performace.
- Heston 3y agoIn a dynamically typed language, that's what comments are for. Since you didn't need types specified in the first place, why would you have trouble interacting with it? Comprehensibility and correctness are just as important as performance.
- nestorD 3y agoUsing typed dependencies makes the Python IDE experience significantly nicer.
- dalf 3y agomypyc does that: https://github.com/mypyc/mypyc https://github.com/mypyc/mypyc > Mypyc compiles Python modules to C extensions. It uses standard Python type hints to generate fast code. Mypyc uses mypy to perform type checking and type inference. > Mypyc can compile anything from one module to an entire codebase. The mypy project has been using mypyc to compile mypy since 2019, giving it a 4x performance boost over regular Python. I have not experience a 4x boost, rather between 1.5x and 2x. I guess it depends on the code.