-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Add type hints for ImageCms #7913
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| nitpick_ignore = [ | ||
| # sphinx does not understand `typing.Literal[-1]` | ||
| ("py:obj", "typing.Literal[-1, 1]"), | ||
| ] |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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.
src/PIL/ImageCms.py
Outdated
| raise PyCMSError(msg) from e | ||
| else: | ||
| # colorTemp is unused if colorSpace != "LAB" | ||
| colorTemp = 0.0 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.)
src/PIL/ImageCms.py
Outdated
| outMode: str, | ||
| renderingIntent: Intent = Intent.PERCEPTUAL, | ||
| proofRenderingIntent: Intent = Intent.ABSOLUTE_COLORIMETRIC, | ||
| flags: Flags | int = Flags.SOFTPROOFING, |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
Co-authored-by: Hugo van Kemenade <[email protected]>
|
Thanks! |
Changes proposed in this pull request:
ImageCmsandImageCms.core;ImageCms.core.profile_tobytes- this cannot be called via the non-core functions thanks to a type check inImageCms.ImageCmsProfile().ImageCms.rstto match the new ones in_imagingcms.pyi.