Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Python 3 fixes - specify binary vs unicode behavior of temporary_file() and stdio_as() #6226
Python 2 allows us to freely mix bytes and unicode with IO. Python 3 forces us to choose between bytes vs unicode.
This led to failing unit tests for
Our code base has mixed use of
Hence, I think the best approach is to enable turning on or off binary mode, with a default given.
The defaults should emulate Python 3's native implementation (principle of least surprise), as discussed below.
In both Py2 and Py3,
So, I kept the default to bytes.
So, I changed
This change shouldn't break anything in Python 2, because it allows for intermixing string types. That's great, because it means that we can incrementally choose whether something should be text vs bytes.
Should I also add unit tests around this new behavior? I'm not sure what type of test would be meaningful - something like asserting that you can't write unicode to a binary file seems repetitive to me as Python provides this functionality and error handling.
There are 4 combinations we're introducing:
Some of these don't seem to work together, like binary files replacing unicode std.
referenced this pull request
Jul 24, 2018
Rather than adding new tests, getting the existing tests running in Python3 is probably the highest priority. If we don't already have functionality exercising the case, then it's a "tree falling in the forest" situation.