This is an archive of the discontinued LLVM Phabricator instance.

Python2/3 compatibility - StringIO
ClosedPublic

Authored by serge-sans-paille on Dec 3 2018, 2:40 AM.

Diff Detail

Repository
rL LLVM

Event Timeline

serge-sans-paille retitled this revision from Python2/3 compatibility to Python2/3 compatibility - StringIO.Dec 3 2018, 2:52 AM

Can you comment on whether the differences between StringIO and io.StringIO might be significant? https://stackoverflow.com/a/49795277

joerg added inline comments.Dec 3 2018, 4:10 AM
bindings/python/tests/cindex/test_translation_unit.py
96 ↗(On Diff #176337)

Move it to the import list at the top of the file.

tools/scan-view/share/ScanView.py
110 ↗(On Diff #176337)

This and the following cases want byte IO, don't they?

StringIO is obsoleted in python3, replaced by io.StringIO.
Yet io.StringIO only handles unicode string, while StringIO.StringIO only handles str, i.e. bytes.
serge-sans-paille marked an inline comment as done.Dec 3 2018, 5:35 AM
serge-sans-paille added inline comments.
tools/scan-view/share/ScanView.py
110 ↗(On Diff #176337)

Yeah, it's probably safer. It really depends on the content of `e`. It also appears that Python 2.7 supports io.BytesIO, so I'd rather use that uniformly.

Use BytesIO as a repalcement... it more closely matches StringIO.StringIO

Update StringIO conversion after more testing.

tools/scan-view/share/ScanView.py
115 ↗(On Diff #176568)

With Python 2 this fails with:
TypeError: unicode argument expected, got 'str'

michaelplatings requested changes to this revision.Dec 18 2018, 9:32 AM
This revision now requires changes to proceed.Dec 18 2018, 9:32 AM
michaelplatings requested changes to this revision.Jan 2 2019, 9:50 AM
michaelplatings added inline comments.
bindings/python/tests/cindex/test_translation_unit.py
97 ↗(On Diff #179060)

May as well make this >= 3

tools/clang-format/clang-format-diff.py
32 ↗(On Diff #179060)

May as well make this >= 3

tools/scan-view/share/ScanView.py
17 ↗(On Diff #179060)

May as well make this >= 3

288 ↗(On Diff #179060)

Why is this necessary? send_string returns a BytesIO object so why create a different one?

This revision now requires changes to proceed.Jan 2 2019, 9:50 AM
serge-sans-paille marked 4 inline comments as done.
This revision is now accepted and ready to land.Jan 3 2019, 4:56 AM
This revision was automatically updated to reflect the committed changes.