4

I've just installed a Pillow package to my virtualenv. Doing this:

from PIL import Image, ImageFont, ImageDraw
ImageFont.load_path('some_path')

I'm getting an error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/net/isilonP/public/rw/homes/cbl_adm/.virtualenvs/chembl_webservices/lib/python2.7/site-packages/PIL/ImageFont.py", line 264, in load_path
    if not isinstance(filename, "utf-8"):
TypeError: isinstance() arg 2 must be a class, type, or tuple of classes and types

And indeed, if you check official gihub repository (https://github.com/python-imaging/Pillow/blob/master/PIL/ImageFont.py#L264), you can see this construct:

if not isinstance(filename, "utf-8"):
    ...

My question is: How do I replace it with something which actually works?

troy_frommer
  • 102
  • 1
  • 21
mnowotka
  • 16,430
  • 18
  • 88
  • 134

1 Answers1

2

Someone overlooked testing that method; the correct incantation is:

if not isinstance(filename, str):
    # ...

because the rest of the code proceeds to turn it into a str, for both Python 2 and Python 3.

I've issued a pull request, after talking with the maintainer on IRC.

Update: the patch has now been merged.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343