8000 FIX: fix importing backend with non-ascii characters by tacaswell · Pull Request #11957 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

FIX: fix importing backend with non-ascii characters #11957

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

Merged
merged 1 commit into from
Sep 1, 2018

Conversation

tacaswell
Copy link
Member

The issue is that the lines coming out of traceback.format_stack()
are bytes (aka python2 str). This file uses unicode_literals so
the string literals are unicode. If any of the paths in the stack
have non-ascii we get UnicodeDecode exceptions when trying to convert
the byte strings to unicode with ascii.

The str calls will have no effect on python3 and down-cast the
unicode to bytes so the operations will work.

A better fix would be to sort out what encoding the bytes from
format_stack are in and convert them to unicode, but this is simpler
and is unlikely to make things worse than they were.

closes #11955

PR Summary

PR Checklist

  • Has Pytest style unit tests
  • Code is Flake 8 compliant
  • New features are documented, with examples if plot related
  • Documentation is sphinx and numpydoc compliant
  • Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
  • Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

@tacaswell
Copy link
Member Author

This falls under the umbrella of things that should be fixed as it is an import error that users can not work around (I don't think telling users to restrict their directory names to only ascii (particularly if the non-ascii is coming from their name as part of their username) is an acceptable 'work around').

@tacaswell
Copy link
Member Author

Appveyor did not fire on this for some reason...

Copy link
Member
@timhoffm timhoffm left a comment

Choose a reason for hiding this comment

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

Maybe add a comment, so that the str() calls will not be accidentially removed.

OTOH this is just relevant for 2.x and we're not likely to change much in that codebase anymore.

The issue is that the lines coming out of `traceback.format_stack()`
are bytes (aka python2 str).  This file uses `unicode_literals` so
the string literals are unicode.  If any of the paths in the stack
have non-ascii we get UnicodeDecode exceptions when trying to convert
the byte strings to unicode with ascii.

The `str` calls will have no effect on python3 and down-cast the
unicode to bytes so the operations will work.

A better fix would be to sort out what encoding the bytes from
`format_stack` are in and convert them to unicode, but this is simpler
and is unlikely to make things worse than they were.

closes matplotlib#11955
@tacaswell tacaswell force-pushed the fix_unicode_traceback branch from 66e2eca to 69b4233 Compare August 28, 2018 22:01
@tacaswell
Copy link
Member Author

This code is not on master branch. but added a comment just to be safe.

@jklymak jklymak merged commit 3156af0 into matplotlib:v2.2.x Sep 1, 2018
@tacaswell tacaswell deleted the fix_unicode_traceback branch September 2, 2018 16:03
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
0