Mutating immutable objects with ctypes

To me, this ‘gotcha’ comment is not only a distraction from the subject of the thread, but is wrong. @kknechtel said “within Python”. The SO answer uses the CPython implementation’s interface to foreign non-Python functions. So “within CPython with cytpes or similar non-Python function access allowed, int object values can be mutated”. Karl, please feel free to write sensibly, as you did, without adding a caveat to every comment.

Most every statement in the Python docs inplicitly assumes that one has not called an implementation-specific foreign function that contradicts the statement. The docs effectively describe Python behavior on a pure Python interpreter that does not have such possibilities. Github python/cpython Issues that report “by using ctypes I made CPython misbehave” get rejected and closed.

4 Likes