
On Tue, Mar 31, 2020 at 07:32:11PM -0000, jdveiga@gmail.com wrote:
If I understand you are proposing a change from StringIO `write` method to `+=` operator. Is it right?
No, that is not correct. The StringIO.write() method will not be changed or removed. The proposal is to extend the class with the `+=` operator which will add as equivalent to calling write().
I cannot see any advantage on this proposal since there is no real change in the implementation of StringIO. Or are you proposing any change in the underlying implementation and I have missed that point?
This proposal isn't about enhancing StringIO's functionality. The purpose of this proposal is targetted at people who are using string concatenation instead of assembling a list then calling join. It is about leveraging StringIO's ability to behave as a string builder to give people a minimally invasive change from the string concatenation anti-pattern: buf = '' # repeated many times buf += 'substring' to something which can be efficient on all Python interpreters: buf = StringIO() buf += 'substring' buf = buf.getvalue()
In this case, I disagree with you: StringIO is a stream and I think that it is wrong to make it to "look & feel" like a string. That is my opinion.
Paul has not suggested making StringIO look and feel like a string. Nobody is going to add 45+ string methods to StringIO. This is a minimal extension to the StringIO class which will allow people to improve their string building code with a minimal change. -- Steven