Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix stdout()/stderr() helpers for Python 3 #254

Merged
merged 1 commit into from
May 9, 2014

Conversation

living180
Copy link
Contributor

On Python 3, the core.stdout() and core.stderr() helper functions were attempting to concatenate the message encoded as a bytestring with a unicode string containing a newline, which raises a TypeError. Fix this by concatenating the newline first, and then only encoding the result if on Python 2, since Python 3 wants unicode strings anyway.

On Python 3, the core.stdout() and core.stderr() helper functions were
attempting to concatenate the message encoded as a bytestring with a
unicode string containing a newline, which raises a TypeError.  Fix this
by concatenating the newline first, and then only encoding the result if
on Python 2, since Python 3 wants unicode strings anyway.

Signed-off-by: Daniel Harding <dharding@living180.net>
@ghost
Copy link

ghost commented May 8, 2014

What about a simpler solution like .write(encode(msg) + b'\n')?

@living180
Copy link
Contributor Author

What about a simpler solution like .write(encode(msg) + b'\n')?

That doesn't work on Python 3, because in that case .write() expects a unicode string, not a bytestring.

@ghost
Copy link

ghost commented May 8, 2014

Oh yeah, true. So the source of the error isn't only the concatenation.

@living180
Copy link
Contributor Author

Right. The first solution I tried was .write(encode(msg + '\n')), but that also raises a TypeError on Python 3.

davvid added a commit that referenced this pull request May 9, 2014
Fix stdout()/stderr() helpers for Python 3
@davvid davvid merged commit 13de53e into git-cola:master May 9, 2014
@living180 living180 deleted the py3_fix_stdout_stderr branch May 9, 2014 13:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants