Search code examples
pythondynamicstaticcomputer-sciencecx-freeze

Can a compiled python code be called dynamically typed anymore?


There are many ways available on internet telling about how to compile a python code using cython, cx_freeze etc. But does a compiled code can act as dynamically typed language?


Solution

  • If you want to bend words enough, all dynamically typed language simply have values of the type "any", from that view, even uncompiled Python is "statically typed". However, that is not a super-useful view.

    But, it would depend exactly how the compilation is done. If the compiled code is simply using the PyObject type, it's definitely still dynamically typed.

    If the compiler does type inference and statically types some values as more restrictive types, it's still dynamically typed (but with some narrowly typed bits).

    Only at the point where all (or at least essentially all) values have been statically typed to more narrow types could we consider the result as statically typed.