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
Prev Previous commit
DOC: add note about encoding choice
  • Loading branch information
tacaswell committed Oct 21, 2017
commit ab4a69136d4e4f270c05eade665ef9d7edc89ebd
2 changes: 2 additions & 0 deletions lib/matplotlib/dviread.py
Original file line number Diff line number Diff line change
Expand Up @@ -1031,6 +1031,8 @@ def find_tex_file(filename, format=None):
"""

if six.PY3:
# we expect these to always be ascii encoded, but use utf-8
# out of caution
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):
Expand Down