Pillow icon indicating copy to clipboard operation
Pillow copied to clipboard

Deprecate getdata(), in favour of new get_flattened_data()

Open radarhere opened this issue 1 month ago • 0 comments

#9261 reports that pyright has a problem when iterating over the core Imaging instance returned from im.getdata().

There is already a comment in our codebase that returning a core Imaging instance from getdata() is a potential pitfall. https://github.com/python-pillow/Pillow/blob/76f04b46c563155a66a7fe92f500e7e8e9d6e096/src/PIL/Image.py#L1447

It would be better for users not to be given a C object they are unfamiliar with.

While users could adapt their code to getchannel() and tobytes() with some manipulation instead, I expect there would be pushback against removing this method entirely.

In practice, I expect that we could just change the output to a tuple, and most if not all code would continue to work, but I understand that changing the return type suddenly is not great in theory.

So this PR suggests deprecating the method, as a replacement, I have added get_flattened_data(), converting the core Imaging instance to a tuple.

radarhere avatar Nov 06 '25 09:11 radarhere