Skip to content

Check return types #9045

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Check return types #9045

wants to merge 3 commits into from

Conversation

radarhere
Copy link
Member

This is part of #8362 - I'm hoping to break down that PR into easier-to-review chunks.

  1. Assert getpixel() returns a tuple, before using index access, since it might also return a float or None.

    Pillow/src/PIL/Image.py

    Lines 1645 to 1647 in a370209

    def getpixel(
    self, xy: tuple[int, int] | list[int]
    ) -> float | tuple[int, ...] | None:
  2. Assert that getcolors() does not return None, because checking length or using index access.

    Pillow/src/PIL/Image.py

    Lines 1415 to 1417 in a370209

    def getcolors(
    self, maxcolors: int = 256
    ) -> list[tuple[int, tuple[int, ...]]] | list[tuple[int, float]] | None:
  3. Assert that getpalette() does not return None before slicing a list.
    def getpalette(self, rawmode: str | None = "RGB") -> list[int] | None:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant