Skip to content

Deprecate putpixel value lists#9586

Open
radarhere wants to merge 1 commit intopython-pillow:mainfrom
radarhere:putpixel_deprecate
Open

Deprecate putpixel value lists#9586
radarhere wants to merge 1 commit intopython-pillow:mainfrom
radarhere:putpixel_deprecate

Conversation

@radarhere
Copy link
Copy Markdown
Member

Resolves #9584

putpixel() says that value accepts a list.

Pillow/src/PIL/Image.py

Lines 2176 to 2178 in 4e0aeba

def putpixel(
self, xy: tuple[int, int], value: float | tuple[int, ...] | list[int]
) -> None:

However, while this works for palette-based values, the issue has pointed out that it doesn't otherwise. When it calls _getink, _getink raises errors that

PyErr_SetString(PyExc_TypeError, "color must be int or tuple");

We could change _getink to accept lists, but updating this common error message would mean that paste(), new() and ImageDraw inks should all then accept lists. It would seem simpler to accept that this is an outlier, and to prevent putpixel from accepting lists as a value.

Because this is working for palette-based colors, I suggest deprecating that functionality first.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Image.putpixel incorrectly labels supported arguments in type annotations

1 participant