do not allow ImageCms.core.CmsProfile to be instantiated directly

This commit is contained in:
Nulano 2024-01-02 00:25:39 +01:00
parent afd6e1fa29
commit 047a0d2a64
2 changed files with 9 additions and 7 deletions

View File

@ -19,6 +19,7 @@ from .helper import (
assert_image_similar,
assert_image_similar_tofile,
hopper,
is_pypy,
)
try:
@ -501,11 +502,7 @@ def test_non_ascii_path(tmp_path: Path) -> None:
def test_profile_typesafety() -> None:
"""Profile init type safety
prepatch, these would segfault, postpatch they should emit a typeerror
"""
# does not segfault
with pytest.raises(TypeError, match="Invalid type for Profile"):
ImageCms.ImageCmsProfile(0).tobytes()
with pytest.raises(TypeError, match="Invalid type for Profile"):
@ -517,6 +514,13 @@ def test_profile_typesafety() -> None:
with pytest.raises(TypeError):
ImageCms.core.profile_tobytes(1)
if not is_pypy():
# core profile should not be directly instantiable
with pytest.raises(TypeError):
ImageCms.core.CmsProfile()
with pytest.raises(TypeError):
ImageCms.core.CmsProfile(0)
def assert_aux_channel_preserved(
mode: str, transform_in_place: bool, preserved_channel: str

View File

@ -1511,8 +1511,6 @@ setup_module(PyObject *m) {
PyObject *v;
int vn;
CmsProfile_Type.tp_new = PyType_GenericNew;
/* Ready object types */
PyType_Ready(&CmsProfile_Type);
PyType_Ready(&CmsTransform_Type);