Skip to content

Commit 047a0d2

Browse files
committed
do not allow ImageCms.core.CmsProfile to be instantiated directly
1 parent afd6e1f commit 047a0d2

2 files changed

Lines changed: 9 additions & 7 deletions

File tree

Tests/test_imagecms.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
assert_image_similar,
2020
assert_image_similar_tofile,
2121
hopper,
22+
is_pypy,
2223
)
2324

2425
try:
@@ -501,11 +502,7 @@ def test_non_ascii_path(tmp_path: Path) -> None:
501502

502503

503504
def test_profile_typesafety() -> None:
504-
"""Profile init type safety
505-
506-
prepatch, these would segfault, postpatch they should emit a typeerror
507-
"""
508-
505+
# does not segfault
509506
with pytest.raises(TypeError, match="Invalid type for Profile"):
510507
ImageCms.ImageCmsProfile(0).tobytes()
511508
with pytest.raises(TypeError, match="Invalid type for Profile"):
@@ -517,6 +514,13 @@ def test_profile_typesafety() -> None:
517514
with pytest.raises(TypeError):
518515
ImageCms.core.profile_tobytes(1)
519516

517+
if not is_pypy():
518+
# core profile should not be directly instantiable
519+
with pytest.raises(TypeError):
520+
ImageCms.core.CmsProfile()
521+
with pytest.raises(TypeError):
522+
ImageCms.core.CmsProfile(0)
523+
520524

521525
def assert_aux_channel_preserved(
522526
mode: str, transform_in_place: bool, preserved_channel: str

src/_imagingcms.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1511,8 +1511,6 @@ setup_module(PyObject *m) {
15111511
PyObject *v;
15121512
int vn;
15131513

1514-
CmsProfile_Type.tp_new = PyType_GenericNew;
1515-
15161514
/* Ready object types */
15171515
PyType_Ready(&CmsProfile_Type);
15181516
PyType_Ready(&CmsTransform_Type);

0 commit comments

Comments
 (0)