Improve type hints
This is part of https://github.com/python-pillow/Pillow/pull/8362 - I'm hoping to break down that PR into easier-to-review chunks.
-
A tile's
argsmight be a tuple, string or None. https://github.com/python-pillow/Pillow/blob/c8d98d56a02e0729f794546d6f270b3cea5baecf/src/PIL/ImageFile.py#L101-L105 Assert thatargsis a tuple before accessing a value by index. -
_getmpmay return a dict or None. https://github.com/python-pillow/Pillow/blob/c8d98d56a02e0729f794546d6f270b3cea5baecf/src/PIL/JpegImagePlugin.py#L528 Assert that it is not None before using a key. -
Pixel access might return a tuple or a float. https://github.com/python-pillow/Pillow/blob/c8d98d56a02e0729f794546d6f270b3cea5baecf/src/PIL/_imaging.pyi#L13-L14 Assert that it is a tuple before checking one of the channel values.
-
load()might return None. https://github.com/python-pillow/Pillow/blob/c8d98d56a02e0729f794546d6f270b3cea5baecf/src/PIL/Image.py#L880 Assert that it isn't None before getting pixel data for a particular co-ordinate. -
getcolors()might return None. https://github.com/python-pillow/Pillow/blob/c8d98d56a02e0729f794546d6f270b3cea5baecf/src/PIL/Image.py#L1411-L1413 Assert that it isn't None before checking how much a colour is used.