String immutability in CPython violated

fuzzy, python, string

Solution

This bug was resolved back in February; update your version.

To answer your question, yes, there are several ways to modify immutable types at the C level. The security implications are unknown, and possibly even unknowable, at this point.

Problem

This is more of an 'interesting' phenomena I encountered in a Python module that I'm trying to understand, rather than a request for help (though a solution would also be useful). ``` >>> import fuzzy >>> s = fuzzy.Soundex(4) >>> a = "apple" >>> b = a >>> sdx_a = s(a) >>> sdx_a 'A140' >>> a 'APPLE' >>> b 'APPLE' ``` Yeah, so the fuzzy module totally violates the immutability of strings in Python. Is it able to do this because it is a C-extension? And does this constitute an error in CPython as well as the module, or even a security risk? Also, can anyone think of a way to get around this behaviour? I would like to be able to keep the original capitalisation of the string. Cheers, Alex

Original source