Deprecate getdata(), in favour of new get_flattened_data() - #9292
Conversation
042abcf to
2dfca16
Compare
e513b4c to
9ef11ec
Compare
9ef11ec to
d15c30a
Compare
hugovk
left a comment
There was a problem hiding this comment.
Do we have an idea of how widely used getdata is?
| Image getdata() | ||
| ~~~~~~~~~~~~~~~ | ||
|
|
||
| .. deprecated:: 12.2.0 |
There was a problem hiding this comment.
| .. deprecated:: 12.2.0 | |
| .. deprecated:: 12.1.0 |
And update from docs/releasenotes/12.2.0.rst
|
|
hugovk
left a comment
There was a problem hiding this comment.
That is quite a lot, but we can try it and see how it goes.
This PR contains the following updates: | Package | Change | [Age](https://docs.renovatebot.com/merge-confidence/) | [Confidence](https://docs.renovatebot.com/merge-confidence/) | |---|---|---|---| | [pillow](https://github.com/python-pillow/Pillow) ([changelog](https://github.com/python-pillow/Pillow/releases)) | `<12.0.1,>=12.0.0` → `<12.1.1,>=12.1.0` |  |  | --- ### Release Notes <details> <summary>python-pillow/Pillow (pillow)</summary> ### [`v12.1.0`](https://github.com/python-pillow/Pillow/releases/tag/12.1.0) [Compare Source](python-pillow/Pillow@12.0.0...12.1.0) <https://pillow.readthedocs.io/en/stable/releasenotes/12.1.0.html> #### Deprecations - Deprecate getdata(), in favour of new get\_flattened\_data() [#​9292](python-pillow/Pillow#9292) \[[@​radarhere](https://github.com/radarhere)] #### Documentation - Specify APNG duration type when opening [#​9368](python-pillow/Pillow#9368) \[[@​radarhere](https://github.com/radarhere)] - Added release notes for [#​9350](python-pillow/Pillow#9350) [#​9366](python-pillow/Pillow#9366) \[[@​radarhere](https://github.com/radarhere)] - Update ImageMorph documentation [#​9349](python-pillow/Pillow#9349) \[[@​radarhere](https://github.com/radarhere)] - Docs: update major bump cadence [#​9334](python-pillow/Pillow#9334) \[[@​hugovk](https://github.com/hugovk)] - Add release notes for [#​9070](python-pillow/Pillow#9070) [#​9320](python-pillow/Pillow#9320) \[[@​radarhere](https://github.com/radarhere)] - Updated Ubuntu version [#​9306](python-pillow/Pillow#9306) \[[@​radarhere](https://github.com/radarhere)] - Update macOS tested Pillow versions [#​9265](python-pillow/Pillow#9265) \[[@​radarhere](https://github.com/radarhere)] #### Dependencies - Update harfbuzz to 12.3.0 [#​9355](python-pillow/Pillow#9355) \[[@​radarhere](https://github.com/radarhere)] - Update xz to 5.8.2 [#​9343](python-pillow/Pillow#9343) \[[@​radarhere](https://github.com/radarhere)] - Updated libjpeg-turbo to 3.1.3 [#​9333](python-pillow/Pillow#9333) \[[@​radarhere](https://github.com/radarhere)] - Updated zlib-ng to 2.3.2 [#​9324](python-pillow/Pillow#9324) \[[@​radarhere](https://github.com/radarhere)] - Updated libpng to 1.6.53 [#​9325](python-pillow/Pillow#9325) \[[@​radarhere](https://github.com/radarhere)] - Update actions/checkout action to v6 [#​9323](python-pillow/Pillow#9323) \[@​[renovate\[bot\]](https://github.com/apps/renovate)] - Update dependency mypy to v1.19.0 [#​9322](python-pillow/Pillow#9322) \[@​[renovate\[bot\]](https://github.com/apps/renovate)] - Updated libpng to 1.6.51 [#​9305](python-pillow/Pillow#9305) \[[@​radarhere](https://github.com/radarhere)] - Updated brotli to 1.2.0 [#​9284](python-pillow/Pillow#9284) \[[@​radarhere](https://github.com/radarhere)] - Update libimagequant to 4.4.1 [#​9301](python-pillow/Pillow#9301) \[[@​radarhere](https://github.com/radarhere)] - Update zlib-ng to 2.3.1, except on manylinux2014 aarch64 [#​9312](python-pillow/Pillow#9312) \[[@​radarhere](https://github.com/radarhere)] - Updated harfbuzz to 12.2.0 [#​9289](python-pillow/Pillow#9289) \[[@​radarhere](https://github.com/radarhere)] - Update github-actions [#​9277](python-pillow/Pillow#9277) \[@​[renovate\[bot\]](https://github.com/apps/renovate)] #### Testing - Replace pre-commit with prek [#​9360](python-pillow/Pillow#9360) \[[@​hugovk](https://github.com/hugovk)] - Test PyQt6 on Python 3.14 on Windows [#​9353](python-pillow/Pillow#9353) \[[@​radarhere](https://github.com/radarhere)] - Test 32-bit Windows on Windows Server 2022 [#​9345](python-pillow/Pillow#9345) \[[@​radarhere](https://github.com/radarhere)] - Correct variable type [#​9335](python-pillow/Pillow#9335) \[[@​radarhere](https://github.com/radarhere)] - Fix `ResourceWarning`s in `selftest.py` [#​9332](python-pillow/Pillow#9332) \[[@​hugovk](https://github.com/hugovk)] - Fix testing good P mode BMP images [#​9319](python-pillow/Pillow#9319) \[[@​radarhere](https://github.com/radarhere)] - Test Python 3.15 pre-release [#​9331](python-pillow/Pillow#9331) \[[@​hugovk](https://github.com/hugovk)] - Test ImageFont.ImageFont, in case freetype2 is not supported [#​9287](python-pillow/Pillow#9287) \[[@​radarhere](https://github.com/radarhere)] - Add Fedora 43 [#​9290](python-pillow/Pillow#9290) \[[@​radarhere](https://github.com/radarhere)] - Remove Fedora 41 [#​9260](python-pillow/Pillow#9260) \[[@​radarhere](https://github.com/radarhere)] #### Type hints - Add ImageFile context manager [#​9367](python-pillow/Pillow#9367) \[[@​radarhere](https://github.com/radarhere)] - Assert fp is not None [#​8617](python-pillow/Pillow#8617) \[[@​radarhere](https://github.com/radarhere)] - Added return type to ImageFile \_close\_fp() [#​9356](python-pillow/Pillow#9356) \[[@​radarhere](https://github.com/radarhere)] - Use different variables for Image and ImageFile instances [#​9316](python-pillow/Pillow#9316) \[[@​radarhere](https://github.com/radarhere)] - Correct variable type [#​9335](python-pillow/Pillow#9335) \[[@​radarhere](https://github.com/radarhere)] - Improve type hints [#​9317](python-pillow/Pillow#9317) \[[@​radarhere](https://github.com/radarhere)] - Use different variables for Image and ImageFile instances [#​9268](python-pillow/Pillow#9268) \[[@​radarhere](https://github.com/radarhere)] - Added type hints [#​9269](python-pillow/Pillow#9269) \[[@​radarhere](https://github.com/radarhere)] - Correct **getitem** return type [#​9264](python-pillow/Pillow#9264) \[[@​radarhere](https://github.com/radarhere)] #### Other changes - Simplify band splitting [#​9291](python-pillow/Pillow#9291) \[[@​radarhere](https://github.com/radarhere)] - Support saving APNG float durations [#​9365](python-pillow/Pillow#9365) \[[@​radarhere](https://github.com/radarhere)] - Allow 1 mode images in MorphOp [#​9348](python-pillow/Pillow#9348) \[[@​radarhere](https://github.com/radarhere)] - Use minimum supported Python version for Lint [#​9364](python-pillow/Pillow#9364) \[[@​radarhere](https://github.com/radarhere)] - Allow for duplicate font variation styles [#​9362](python-pillow/Pillow#9362) \[[@​radarhere](https://github.com/radarhere)] - Call parent verify method [#​9357](python-pillow/Pillow#9357) \[[@​radarhere](https://github.com/radarhere)] - Return LUT from LutBuilder build\_default\_lut() [#​9350](python-pillow/Pillow#9350) \[[@​radarhere](https://github.com/radarhere)] - Simplify WebP code [#​9329](python-pillow/Pillow#9329) \[[@​radarhere](https://github.com/radarhere)] - Use unsigned long for DWORD [#​9352](python-pillow/Pillow#9352) \[[@​radarhere](https://github.com/radarhere)] - Cast to UINT32 before shifting bits [#​9347](python-pillow/Pillow#9347) \[[@​radarhere](https://github.com/radarhere)] - \[pre-commit.ci] pre-commit autoupdate [#​9318](python-pillow/Pillow#9318) \[@​[pre-commit-ci\[bot\]](https://github.com/apps/pre-commit-ci)] - Allow window ID to be passed to ImageGrab.grab() on macOS [#​9070](python-pillow/Pillow#9070) \[[@​yankeguo](https://github.com/yankeguo)] - Apply encoder options when saving multiple PNG frames [#​9300](python-pillow/Pillow#9300) \[[@​radarhere](https://github.com/radarhere)] - Read all non-zero transparency from mode 1 PNG images as 255 [#​9282](python-pillow/Pillow#9282) \[[@​radarhere](https://github.com/radarhere)] - Support writing IFD, SIGNED\_RATIONAL and InkNames TIFF tags [#​9276](python-pillow/Pillow#9276) \[[@​radarhere](https://github.com/radarhere)] - Remove unused modes [#​9275](python-pillow/Pillow#9275) \[[@​radarhere](https://github.com/radarhere)] - Correct allocating new color to RGBA palette [#​9313](python-pillow/Pillow#9313) \[[@​radarhere](https://github.com/radarhere)] - Close image on ImageFont exception [#​9304](python-pillow/Pillow#9304) \[[@​radarhere](https://github.com/radarhere)] - Reapply "Use macos-latest for iOS arm64 simulator" [#​9259](python-pillow/Pillow#9259) \[[@​radarhere](https://github.com/radarhere)] - Escape period in pre-commit-config [#​9036](python-pillow/Pillow#9036) \[[@​radarhere](https://github.com/radarhere)] - Add Apache-2.0 notice to IcoImagePlugin [#​8947](python-pillow/Pillow#8947) \[[@​stefan6419846](https://github.com/stefan6419846)] - \[pre-commit.ci] pre-commit autoupdate [#​9288](python-pillow/Pillow#9288) \[@​[pre-commit-ci\[bot\]](https://github.com/apps/pre-commit-ci)] - Simplify code now that I;16\* modes are the only IMAGING\_TYPE\_SPECIAL [#​9263](python-pillow/Pillow#9263) \[[@​radarhere](https://github.com/radarhere)] - Remove BytesIO from DdsImagePlugin [#​9273](python-pillow/Pillow#9273) \[[@​radarhere](https://github.com/radarhere)] - Fix ZeroDivisionError in DdsImagePlugin [#​9272](python-pillow/Pillow#9272) \[[@​radarhere](https://github.com/radarhere)] - Fix warnings [#​9257](python-pillow/Pillow#9257) \[[@​radarhere](https://github.com/radarhere)] </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR is behind base branch, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0Mi42OS4yIiwidXBkYXRlZEluVmVyIjoiNDIuNjkuMiIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOlsidHlwZS9kZXBlbmRlbmNpZXMiXX0=--> Reviewed-on: https://git.tainton.uk/repos/webexmemebot/pulls/542 Co-authored-by: renovate[bot] <renovate-bot@git.tainton.uk> Co-committed-by: renovate[bot] <renovate-bot@git.tainton.uk>
addresses Pillow's deprecation of `getdata`. see: python-pillow/Pillow#9292 Signed-off-by: cinereal <cinereal@riseup.net>
|
Hmm. I would maybe reconsider the full deprecation of (EDIT: another option could be to to allow PixelAccess objects, as returned from |
Could you expand upon this scenario? If it wasn't linear, I'd say that
I think it just meant that the C API is not intended to be called by user Python code, and |
$ python3
Python 3.14.6 (main, Jun 10 2026, 10:03:53) [Clang 17.0.0 (clang-1700.6.4.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> # macOS's Activity Monitor shows this Python to use 14.1 MB of memory
>>> from PIL import Image
>>> i = Image.new("RGB", (1024, 1024), 42)
>>> # macOS's Activity Monitor shows this Python to use 21.7 MB of memory
>>> t = i.get_flattened_data()
>>> # macOS's Activity Monitor shows this Python to use 118.4 MB of memory(and I think peak memory during I could see that users switching to Memory blow-up aside, (lazy) linear iterators interop with the standard library/idioms (that don't work with PixelAccess that requires
Yeap. As said, I can do the work to have |
My idea would be to return a Python class, rather than C, that calls |
#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.