Deprecate getdata(), in favour of new get_flattened_data() #9292
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
#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.Pillow/src/PIL/Image.py
Line 1447 in 76f04b4
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()andtobytes()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.