Skip to content
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

Added type hints to additional tests #8093

Merged
merged 1 commit into from
Jun 1, 2024

Conversation

radarhere
Copy link
Member

No description provided.

@@ -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]
Copy link
Member

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?

Copy link
Member Author

Choose a reason for hiding this comment

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

Tests/test_imagecms.py:212: error: Argument 1 to "getProfileName" has incompatible type "None"; expected
"Union[str, SupportsRead[bytes], CmsProfile, ImageCmsProfile]"  [arg-type]
            ImageCms.getProfileName(None)
                                    ^~~~

The test's intention is to go through

def getProfileName(profile: _CmsProfileCompatible) -> str:

where

Pillow/src/PIL/ImageCms.py

Lines 369 to 371 in c757439

_CmsProfileCompatible = Union[
str, SupportsRead[bytes], core.CmsProfile, ImageCmsProfile
]

and then

Pillow/src/PIL/ImageCms.py

Lines 239 to 240 in c757439

class ImageCmsProfile:
def __init__(self, profile: str | SupportsRead[bytes] | core.CmsProfile) -> None:

to reach
msg = "Invalid type for Profile" # type: ignore[unreachable]

The type is deliberately incorrect.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks!


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]
Copy link
Member

Choose a reason for hiding this comment

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

And this?

Copy link
Member Author

Choose a reason for hiding this comment

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

Tests/test_imagecms.py:532: error: Too many arguments for "CmsProfile"  [call-arg]
                ImageCms.core.CmsProfile(0)
                ^~~~~~~~~~~~~~~~~~~~~~~~~~~

@hugovk hugovk merged commit 33c31cb into python-pillow:main Jun 1, 2024
54 of 55 checks passed
@radarhere radarhere deleted the type_hints_tests branch June 1, 2024 10:45
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.

None yet

2 participants