Pillow icon indicating copy to clipboard operation
Pillow copied to clipboard

Improve type hints

Open radarhere opened this issue 8 months ago • 0 comments

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.

  1. A tile's args might be a tuple, string or None. https://github.com/python-pillow/Pillow/blob/c8d98d56a02e0729f794546d6f270b3cea5baecf/src/PIL/ImageFile.py#L101-L105 Assert that args is a tuple before accessing a value by index.

  2. _getmp may 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.

  3. 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.

  4. 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.

  5. 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.

radarhere avatar Apr 12 '25 04:04 radarhere