
Ask HN: Why can't Python be compiled? - Kepler-295c
The old answer was that types were not known in advance. However with Python 3.6, it&#x27;s possible to give type hints. Given this, is there anything stopping Python being compiled natively?
======
dagw
Cython compiles any python code to C which is then complied normally. If you
provide type hints cython will use that to produce more optimized C code.

That being said the speedup from compiling your untyped python code is
minimal, generally in the 0-40% range. However by adding types to your code
you can often get significant speedups.

------
dozzie
Yes. Exactly the same as before: dynamic typing. Optional type hints don't
change this.

And Python actually _is_ compiled. Where do you think these pyc and pyo files
come from?

