Deprecate ImageCore.id and ImageCore.unsafe_ptrs

This commit is contained in:
Aleksandr Karpinskii 2024-09-02 02:19:44 +04:00
parent f246be7b13
commit 7435a06cbb
4 changed files with 35 additions and 3 deletions

View File

@ -1,11 +1,19 @@
from __future__ import annotations from __future__ import annotations
import pytest
from .helper import hopper from .helper import hopper
def test_sanity() -> None: def test_sanity() -> None:
im = hopper() im = hopper()
type_repr = repr(type(im.getim()))
type_repr = repr(type(im.getim()))
assert "PyCapsule" in type_repr 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"])

View File

@ -136,6 +136,16 @@ Specific WebP Feature Checks
``True`` if the WebP module is installed, until they are removed in Pillow ``True`` if the WebP module is installed, until they are removed in Pillow
12.0.0 (2025-10-15). 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 Removed features
---------------- ----------------

View File

@ -3707,6 +3707,13 @@ _getattr_bands(ImagingObject *self, void *closure) {
static PyObject * static PyObject *
_getattr_id(ImagingObject *self, void *closure) { _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); return PyLong_FromSsize_t((Py_ssize_t)self->image);
} }
@ -3717,6 +3724,13 @@ _getattr_ptr(ImagingObject *self, void *closure) {
static PyObject * static PyObject *
_getattr_unsafe_ptrs(ImagingObject *self, void *closure) { _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( return Py_BuildValue(
"(sn)(sn)(sn)", "(sn)(sn)(sn)",
"image8", "image8",

View File

@ -61,7 +61,7 @@ typedef struct ImagingOutlineInstance *ImagingOutline;
typedef struct ImagingPaletteInstance *ImagingPalette; typedef struct ImagingPaletteInstance *ImagingPalette;
/* handle magics (used with PyCObject). */ /* handle magics (used with PyCObject). */
#define IMAGING_MAGIC "PIL Imaging" #define IMAGING_MAGIC "Pillow Imaging"
/* pixel types */ /* pixel types */
#define IMAGING_TYPE_UINT8 0 #define IMAGING_TYPE_UINT8 0