Static typing [was Re: Python and the need for speed]

Paul Rubin at nospam.invalid
Mon Apr 17 02:18:20 EDT 2017

Steve D'Aprano <steve+python at> writes:
> Since it is *optional*, it is only a hint, not a fact. You can tell the
> compiler that you believe that n will be an int, but it's not guaranteed.

The runtime could check at the entry to the function that n is an int,
and then it wouldn't have to keep re-checking on the inside of a loop.
That's what a JIT compiler does in the absence of annotations, more or
less; but the annotations make life easier for ahead-of-time compilers.
Again this type of thing has been standard in Lisp since the 1960's.

More information about the Python-list mailing list