Improve type hints by radarhere · Pull Request #8883 · python-pillow/Pillow
Navigation Menu
- Notifications You must be signed in to change notification settings
- Fork 2.4k
Conversation
This is part of #8362 - I'm hoping to break down that PR into easier-to-review chunks.
-
A tile's
argsmight be a tuple, string or None.
class _Tile(NamedTuple): codec_name: str extents: tuple[int, int, int, int] | None offset: int = 0 args: tuple[Any, ...] | str | None = None
Assert thatargsis a tuple before accessing a value by index. -
_getmpmay return a dict or None.
def _getmp(self) -> dict[int, Any] | None:
Assert that it is not None before using a key. -
Pixel access might return a tuple or a float.
class PixelAccess: def __getitem__(self, xy: tuple[int, int]) -> float | tuple[int, ...]: ...
Assert that it is a tuple before checking one of the channel values. -
load()might return None.
def load(self) -> core.PixelAccess | None:
Assert that it isn't None before getting pixel data for a particular co-ordinate. -
getcolors()might return None.
def getcolors( self, maxcolors: int = 256 ) -> list[tuple[int, tuple[int, ...]]] | list[tuple[int, float]] | None:
Assert that it isn't None before checking how much a colour is used.
radarhere
changed the title
Improved type hints
Improve type hints
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters