modernize
modernize copied to clipboard
change uses of StringIO
E.g. [c]StringIO.StringIO should be changed to six.BytesIO.
(moved from https://github.com/mitsuhiko/python-modernize/issues/17 )
Again, I think we should (at least by default) avoid trying to guess what the user wants. We've got a number of places in IPython where we use io.StringIO on Python 3 and StringIO.StringIO on Python 2. An off-by-default fixer might be OK, though.
I just ran into this myself and the solution should depend on whether --no-six is specified. If no six is desired then you should probably use io.StringIO as a >= Python 2.6 solution.
I don't think that's quite right:
--no-sixshould mean "I don't want to use six", not a proxy for "this only needs to support Python 2.6 and above". I see your issue #33, so let's discuss this more there.- The right answer for this doesn't just depend on what versions of Python you support. E.g. IPython only supports 2.7 and 3.3+, but we still use StringIO.StringIO in quite a few places on Python 2, because it accepts
str, whereasio.StringIOis strict about only accepting unicode.
Farther along in my Pylint port and I have run into the issues that has led to IPython keeping [c]StringIO.StringIO around. Unfortunately this is one of those places where the Python 2 API was so lenient it doesn't translate well to a str/bytes dichotomy.
If we add an option, say --careful-unicode, for transforming code that is already careful about string types (as suggested in #31), then that option should probably enable a StringIO -> six.BytesIO fixer by default. In other cases we should just leave StringIO alone to be changed manually.
there's since been a six.StringIO