News for hackers. Stuff that matters.
Re:The different uses of Python type hints by Heston on Saturday April 15, 2023 @05:57PM (#35584968)
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?
Re:The different uses of Python type hints by gaganyaan on Saturday April 15, 2023 @06:26PM (#35585223)
Type 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.

Re:The different uses of Python type hints by maleldil on Saturday April 15, 2023 @06:44PM (#35585395)
Similarly 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/

Re:The different uses of Python type hints by abdullahkhalids on Saturday April 15, 2023 @06:58PM (#35585498)
> 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.

Re:The different uses of Python type hints by dragonwriter on Saturday April 15, 2023 @07:32PM (#35585719)
> 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.

Re:The different uses of Python type hints by Heston on Monday April 17, 2023 @02:37PM (#35604683)
In a loosely typed language, that's what comments are for. Since you didn't need types specified in the first place, why would you have trouble with interacting with it? Comprehensibility and correctness are just as important as performance.
Re:The different uses of Python type hints by nestorD on Saturday April 15, 2023 @09:42PM (#35586474)
Using typed dependencies makes the Python IDE experience significantly nicer.
Re:The different uses of Python type hints by dalf on Sunday April 16, 2023 @03:50AM (#35588083)
mypyc does that: 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.