Skip to content

Conversation

@radarhere
Copy link
Member

No description provided.


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!

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
@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

2 participants