[Python-Dev] Type hints -- a mediocre programmer's reaction (original) (raw)

Antoine Pitrou solipsis at pitrou.net
Tue Apr 21 19:36:31 CEST 2015


On Tue, 21 Apr 2015 18:27:50 +0300 Paul Sokolovsky <pmiscml at gmail.com> wrote:

Let me try: MicroPython already uses type annotations for statically typed functions. E.g.

def add(x:int, y:int): return x + y will translate the function to just 2 machine instructions.

That's quite nice.

Oh really, you care to support single-precisions in Numba?

Numba is quite specialized. In our area, single-precision arithmetic can sometimes give double the speed on modern CPUs (especially when LLVM is able to vectorize the code). The speedup can be even larger on a GPU (where double-precision execution resources are scarce). I agree it doesn't make sense for a general-purpose Python compiler.

Anyway, back to your example, it would be done like:

SFloat = float DFloat = float For a random tool out there, "SFloat" and "DFloat" would be just aliases to floats, but Numba will know they have additional semantics behind them. (That assumes that typedefs like SFloat can be accessed in symbolic form - that's certainly possible if you have your own parser/VM, but might worth to think how to do it on "CPython" level).

Fortunately, we don't have our own parser :-) We work from the CPython bytecode.

Regards

Antoine.



More information about the Python-Dev mailing list