Skip to content

Commit

Permalink
Deprecate ImageCore.id and ImageCore.unsafe_ptrs
Browse files Browse the repository at this point in the history
  • Loading branch information
homm committed Sep 1, 2024
1 parent f246be7 commit aa1f7b8
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 3 deletions.
12 changes: 10 additions & 2 deletions Tests/test_image_getim.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
from __future__ import annotations

import pytest

from .helper import hopper


def test_sanity() -> None:
im = hopper()

type_repr = repr(type(im.getim()))

assert "PyCapsule" in type_repr
assert isinstance(im.im.id, int)

with pytest.warns(DeprecationWarning):
assert isinstance(im.im.id, int)

with pytest.warns(DeprecationWarning):
ptrs = dict(im.im.unsafe_ptrs)
assert all(k in ptrs for k in ['image8', 'image32', 'image'])
10 changes: 10 additions & 0 deletions docs/deprecations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,16 @@ Specific WebP Feature Checks
``True`` if the WebP module is installed, until they are removed in Pillow
12.0.0 (2025-10-15).

Get Internal Pointers to Objects
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. deprecated:: 11.0.0

``Image.core.ImageCore.id`` and ``Image.core.ImageCore.unsafe_ptrs``
have been deprecated and will be removed in Pillow 12 (2025-10-15).
They were used for obtaining raw pointers to ``ImageCore`` internals. To interact with
C code, you can use ``Image.core.ImageCore.ptr``, which returns a ``PyCapsule`` object.

Removed features
----------------

Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ addopts = "-ra --color=yes"
testpaths = [
"Tests",
]
markers = "timeout"

[tool.mypy]
python_version = "3.9"
Expand Down
14 changes: 14 additions & 0 deletions src/_imaging.c
Original file line number Diff line number Diff line change
Expand Up @@ -3707,6 +3707,13 @@ _getattr_bands(ImagingObject *self, void *closure) {

static PyObject *
_getattr_id(ImagingObject *self, void *closure) {
if (PyErr_WarnEx(
PyExc_DeprecationWarning,
"id property is deprecated and will be removed in Pillow 12.0",
1
) < 0) {
return NULL;
}
return PyLong_FromSsize_t((Py_ssize_t)self->image);
}

Expand All @@ -3717,6 +3724,13 @@ _getattr_ptr(ImagingObject *self, void *closure) {

static PyObject *
_getattr_unsafe_ptrs(ImagingObject *self, void *closure) {
if (PyErr_WarnEx(
PyExc_DeprecationWarning,
"unsafe_ptrs property is deprecated and will be removed in Pillow 12.0",
1
) < 0) {
return NULL;
}
return Py_BuildValue(
"(sn)(sn)(sn)",
"image8",
Expand Down
2 changes: 1 addition & 1 deletion src/libImaging/Imaging.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ typedef struct ImagingOutlineInstance *ImagingOutline;
typedef struct ImagingPaletteInstance *ImagingPalette;

/* handle magics (used with PyCObject). */
#define IMAGING_MAGIC "PIL Imaging"
#define IMAGING_MAGIC "Pillow Imaging"

/* pixel types */
#define IMAGING_TYPE_UINT8 0
Expand Down

0 comments on commit aa1f7b8

Please sign in to comment.