8000 Fix TypeError: a bytes-like object is required, not 'str' by cgohlke · Pull Request #9292 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Fix TypeError: a bytes-like object is required, not 'str' #9292

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 2 commits into from
Oct 23, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/matplotlib/dviread.py
Original file line number Diff line number Diff line change
Expand Up @@ -1030,6 +1030,12 @@ def find_tex_file(filename, format=None):
The library that :program:`kpsewhich` is part of.
"""

if six.PY3:
if isinstance(filename, bytes):
filename = filename.decode('utf-8', errors='replace')
Copy link
Contributor

Choose a reason for hiding this comment

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

Should probably use https://docs.python.org/3/library/os.html#os.fsdecode here?
For format I dunno what is the correct encoding; that probably is deep into the kpsewhich sources but I guess all relevant formats have ASCII compatible names so utf-8 should just be fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure the filesystem encoding is a better choice for a function searching for a file. Is this even relevant? MikTeX's kpsewhich does not find any non-ASCII file name.

Copy link
Contributor
@anntzer anntzer Oct 6, 2017

Choose a reason for hiding this comment

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

then perhaps add a comment that in practice the encoding is irrelevant -- other than being ASCII-compatible -- because you don't expect non-ASCII filenames to be found (to avoid later head-scratching as to why utf-8).

if isinstance(format, bytes):
format = format.decode('utf-8', errors='replace')

cmd = [str('kpsewhich')]
if format is not None:
cmd += ['--format=' + format]
Expand Down
0