Assert palette is not None by radarhere · Pull Request #8877 · python-pillow/Pillow
This is part of #8362 - I'm hoping to break down that PR into easier-to-review chunks.
Image's palette may be None
>>> from PIL import Image >>> im = Image.new("RGB", (1, 1)) >>> im.palette is None True
So before using it, let's assert that it isn't None.