Skip to content

Un-deprecate getdata(); have it return an ImageLinearAccess object - #9883

Draft
akx wants to merge 1 commit into
python-pillow:mainfrom
akx:image-getdata-linear-access
Draft

Un-deprecate getdata(); have it return an ImageLinearAccess object#9883
akx wants to merge 1 commit into
python-pillow:mainfrom
akx:image-getdata-linear-access

Conversation

@akx

@akx akx commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Follows up on #9292 to un-deprecate getdata(), since get_flattened_data() is not a perfect replacement for linear access to image pixels given its upfront memory and time costs. (See #9292 (comment) for rationales.)

Fixes #9261 (since getdata now returns a real, well-typed iterator/access object). Given x.py like

# pyright: strict
from __future__ import annotations
from PIL import Image
im = Image.new("RGB", (4, 4))
printed = list(im.getdata())

pyright fails on main:

(main) $ uvx --quiet --with pytest --with numpy pyright@1.1.411 x.py
  x.py:5:1 - error: Type of "printed" is partially unknown
    Type of "printed" is "list[Unknown]" (reportUnknownVariableType)
  x.py:5:16 - error: Argument of type "ImagingCore" cannot be assigned to parameter "iterable" of type "Iterable[_T@list]" in function "__init__"
    "ImagingCore" is incompatible with protocol "Iterable[_T@list]"
      "__iter__" is not present (reportArgumentType)
2 errors, 0 warnings, 0 informations

but is fine on this branch:

(image-getdata-linear-access) $ uvx --quiet --with pytest --with numpy pyright@1.1.411 x.py
0 errors, 0 warnings, 0 informations

The optimizations from #9881 still help this too and don't conflict here.

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.

1 participant