Skip to content

Conversation

@nulano
Copy link
Contributor

@nulano nulano commented Mar 28, 2024

Changes proposed in this pull request:

  • Add type hints for ImageCms and ImageCms.core;
  • Add type check to ImageCms.core.profile_tobytes - this cannot be called via the non-core functions thanks to a type check in ImageCms.ImageCmsProfile().
  • Update types in ImageCms.rst to match the new ones in _imagingcms.pyi.

nitpick_ignore = [
# sphinx does not understand `typing.Literal[-1]`
("py:obj", "typing.Literal[-1, 1]"),
]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be fixed in a future release of sphinx: sphinx-doc/sphinx#11904

PyModule_AddObject(m, "CmsProfile", (PyObject *)&CmsProfile_Type);

Py_INCREF(&CmsTransform_Type);
PyModule_AddObject(m, "CmsTransform", (PyObject *)&CmsTransform_Type);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seemed odd to me to expose one of the classes but not the other.

PyObject *v;
int vn;

CmsProfile_Type.tp_new = PyType_GenericNew;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not needed (and incorrect! should call core.profile_open or core.profile_frombytes instead).

I added new tests for this being unset, but on PyPy this is the default value.

raise PyCMSError(msg) from e
else:
# colorTemp is unused if colorSpace != "LAB"
colorTemp = 0.0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is minor, but considering it's unused, what's the advantage of setting it to zero?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The value is passed to PyArg_ParseTuple with the d format. Based on the documentation, my understanding was that this required a float object, not a SupportsFloat object. However, testing with Python 3.11, it seems that a SupportsFloat object is actually accepted, so I'll revert this part of the change.

(Testing with SupportsInt I do get the expected TypeError, so at least that part matches the documentation.)

outMode: str,
renderingIntent: Intent = Intent.PERCEPTUAL,
proofRenderingIntent: Intent = Intent.ABSOLUTE_COLORIMETRIC,
flags: Flags | int = Flags.SOFTPROOFING,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't our discussion in #7671 (comment) about favouring enums over int also apply to the IntFlag of Flags, meaning this could just be flags: Flags?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, you're right. IIRC I might have added int to support the deprecated ImageCms.FLAGS, but that does not have type hints and should not be used anyway.

@hugovk hugovk merged commit 6c55ab2 into python-pillow:main Mar 31, 2024
@hugovk
Copy link
Member

hugovk commented Mar 31, 2024

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants