-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Added type hints to additional tests #8093
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,7 +7,7 @@ | |
| import sys | ||
| from io import BytesIO | ||
| from pathlib import Path | ||
| from typing import Any | ||
| from typing import Any, Literal, cast | ||
|
|
||
| import pytest | ||
|
|
||
|
|
@@ -209,13 +209,13 @@ def test_exceptions() -> None: | |
| ImageCms.buildTransform("foo", "bar", "RGB", "RGB") | ||
|
|
||
| with pytest.raises(ImageCms.PyCMSError, match="Invalid type for Profile"): | ||
| ImageCms.getProfileName(None) | ||
| ImageCms.getProfileName(None) # type: ignore[arg-type] | ||
| skip_missing() | ||
|
|
||
| # Python <= 3.9: "an integer is required (got type NoneType)" | ||
| # Python > 3.9: "'NoneType' object cannot be interpreted as an integer" | ||
| with pytest.raises(ImageCms.PyCMSError, match="integer"): | ||
| ImageCms.isIntentSupported(SRGB, None, None) | ||
| ImageCms.isIntentSupported(SRGB, None, None) # type: ignore[arg-type] | ||
|
|
||
|
|
||
| def test_display_profile() -> None: | ||
|
|
@@ -239,7 +239,7 @@ def test_unsupported_color_space() -> None: | |
| "Color space not supported for on-the-fly profile creation (unsupported)" | ||
| ), | ||
| ): | ||
| ImageCms.createProfile("unsupported") | ||
| ImageCms.createProfile("unsupported") # type: ignore[arg-type] | ||
|
|
||
|
|
||
| def test_invalid_color_temperature() -> None: | ||
|
|
@@ -352,7 +352,7 @@ def test_extended_information() -> None: | |
| p = o.profile | ||
|
|
||
| def assert_truncated_tuple_equal( | ||
| tup1: tuple[Any, ...], tup2: tuple[Any, ...], digits: int = 10 | ||
| tup1: tuple[Any, ...] | None, tup2: tuple[Any, ...], digits: int = 10 | ||
| ) -> None: | ||
| # Helper function to reduce precision of tuples of floats | ||
| # recursively and then check equality. | ||
|
|
@@ -368,6 +368,7 @@ def truncate_tuple(tuple_value: tuple[Any, ...]) -> tuple[Any, ...]: | |
| for val in tuple_value | ||
| ) | ||
|
|
||
| assert tup1 is not None | ||
| assert truncate_tuple(tup1) == truncate_tuple(tup2) | ||
|
|
||
| assert p.attributes == 4294967296 | ||
|
|
@@ -513,22 +514,22 @@ def test_non_ascii_path(tmp_path: Path) -> None: | |
| def test_profile_typesafety() -> None: | ||
| # does not segfault | ||
| with pytest.raises(TypeError, match="Invalid type for Profile"): | ||
| ImageCms.ImageCmsProfile(0).tobytes() | ||
| ImageCms.ImageCmsProfile(0) # type: ignore[arg-type] | ||
| with pytest.raises(TypeError, match="Invalid type for Profile"): | ||
| ImageCms.ImageCmsProfile(1).tobytes() | ||
| ImageCms.ImageCmsProfile(1) # type: ignore[arg-type] | ||
|
|
||
| # also check core function | ||
| with pytest.raises(TypeError): | ||
| ImageCms.core.profile_tobytes(0) | ||
| ImageCms.core.profile_tobytes(0) # type: ignore[arg-type] | ||
| with pytest.raises(TypeError): | ||
| ImageCms.core.profile_tobytes(1) | ||
| ImageCms.core.profile_tobytes(1) # type: ignore[arg-type] | ||
|
|
||
| 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) | ||
| ImageCms.core.CmsProfile(0) # type: ignore[call-arg] | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And this?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
|
|
||
| @pytest.mark.skipif(is_pypy(), reason="fails on PyPy") | ||
|
|
@@ -537,7 +538,7 @@ def test_transform_typesafety() -> None: | |
| with pytest.raises(TypeError): | ||
| ImageCms.core.CmsTransform() | ||
| with pytest.raises(TypeError): | ||
| ImageCms.core.CmsTransform(0) | ||
| ImageCms.core.CmsTransform(0) # type: ignore[call-arg] | ||
|
|
||
|
|
||
| def assert_aux_channel_preserved( | ||
|
|
@@ -637,7 +638,8 @@ def test_auxiliary_channels_isolated() -> None: | |
| continue | ||
|
|
||
| # convert with and without AUX data, test colors are equal | ||
| source_profile = ImageCms.createProfile(src_format[1]) | ||
| src_colorSpace = cast(Literal["LAB", "XYZ", "sRGB"], src_format[1]) | ||
| source_profile = ImageCms.createProfile(src_colorSpace) | ||
| destination_profile = ImageCms.createProfile(dst_format[1]) | ||
| source_image = src_format[3] | ||
| test_transform = ImageCms.buildTransform( | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
What does this warning look like?
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 test's intention is to go through
Pillow/src/PIL/ImageCms.py
Line 807 in c757439
where
Pillow/src/PIL/ImageCms.py
Lines 369 to 371 in c757439
and then
Pillow/src/PIL/ImageCms.py
Lines 239 to 240 in c757439
to reach
Pillow/src/PIL/ImageCms.py
Line 263 in c757439
The type is deliberately incorrect.
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.
Thanks!