It is useful to have the interpreter derive the type of a variable automatically. This on its own is similar to the auto
keyword in C++11. However, in Python variables can change their type after being declared for the first time. This potentially can cause a lot of errors. I haven't seen any reasonable use case for this, besides changing from or to None
.
For performance reasons, PyPy claims to be written in what they call RPython, which goes into this direction. However, it seems like there is neither a standard for this nor a way to make the interpreter complain about type changing.
Is there a way to prevent variables from changing their type in Python?