Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 69b4233

Browse files
committed
FIX: fix importing backend with non-ascii characters
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
1 parent 29ce489 commit 69b4233

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

lib/matplotlib/backends/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@
1212
_log = logging.getLogger(__name__)
1313

1414
backend = matplotlib.get_backend()
15-
_backend_loading_tb = "".join(
15+
# the `str` calls here are to make non-ascii paths work on python2
16+
_backend_loading_tb = str("").join(
1617
line for line in traceback.format_stack()
1718
# Filter out line noise from importlib line.
18-
if not line.startswith(' File "<frozen importlib._bootstrap'))
19+
if not line.startswith(str(' File "<frozen importlib._bootstrap')))
1920

2021

2122
def pylab_setup(name=None):

0 commit comments

Comments
 (0)