modernize icon indicating copy to clipboard operation
modernize copied to clipboard

change uses of StringIO

Open daira opened this issue 11 years ago • 6 comments

E.g. [c]StringIO.StringIO should be changed to six.BytesIO.

(moved from https://github.com/mitsuhiko/python-modernize/issues/17 )

daira avatar Aug 13 '14 00:08 daira

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.

takluyver avatar Aug 13 '14 00:08 takluyver

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.

brettcannon avatar Aug 15 '14 14:08 brettcannon

I don't think that's quite right:

  • --no-six should 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, whereas io.StringIO is strict about only accepting unicode.

takluyver avatar Aug 15 '14 16:08 takluyver

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.

brettcannon avatar Aug 18 '14 14:08 brettcannon

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.

daira avatar Aug 18 '14 21:08 daira

there's since been a six.StringIO

graingert avatar Oct 09 '20 18:10 graingert