Skip to content

Conversation

@takuya1981
Copy link
Contributor

No description provided.

@takuya1981
Copy link
Contributor Author

This PR fixed issue #11615

try:
print(val)
except UnicodeEncodeError:
print(val.encode("utf-8", "backslashreplace").decode())
Copy link
Member

@MrMino MrMino Apr 4, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are the benefits of having try...except here rather than just print(val.encode(...).decode())?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this is question of efficiency. In most case print() will work, so there is no need to do the expensive encode(), then .decode() dance, that would in the end often be no-op.

@Carreau Carreau added this to the 7.23 milestone Apr 14, 2021
@Carreau
Copy link
Member

Carreau commented Apr 14, 2021

I think that it's harmless enough that we can get that in.
Thanks.

@Carreau Carreau merged commit e783d23 into ipython:master Apr 14, 2021
meeseeksmachine pushed a commit to meeseeksmachine/ipython that referenced this pull request Apr 14, 2021
Carreau added a commit that referenced this pull request Apr 17, 2021
…758-on-7.x

Backport PR #12758 on branch 7.x (Fix issue #11615  handle unicode encode error when print stack trace)
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.

3 participants