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

Raise proper TypeError in putpixel #4882

Merged
merged 3 commits into from Sep 3, 2020
Merged

Conversation

nulano
Copy link
Contributor

@nulano nulano commented Aug 19, 2020

Fixes #4876:

  • The existing code silently ignores an OverflowError for 8bpp images, hoping that the int will become a tuple in the next few lines.
  • It also fails to check that the given parameter is a tuple before trying to unpack it, giving the less than useful message SystemError: new style getargs format but argument is not a tuple.
  • Last but not least, passing a non-int value for non-8bpp non-float images (e.g. I;16) gives an even less useful message SystemError: <method 'putpixel' of 'ImagingCore' objects> returned NULL without setting an error.

This PR resolves all of these issues by explicitly raising a TypeError if the parameter can't be converted to an int, or a tuple for an 8bpp image.

Tests/test_image_access.py Outdated Show resolved Hide resolved
Tests/test_image_access.py Outdated Show resolved Hide resolved
Co-authored-by: Hugo van Kemenade <hugovk@users.noreply.github.com>
@hugovk
Copy link
Member

hugovk commented Sep 3, 2020

Thanks! Do you think this should go in the release notes?

https://pillow.readthedocs.io/en/latest/releasenotes/8.0.0.html

@nulano
Copy link
Contributor Author

nulano commented Sep 3, 2020

Probably not. Release notes typically mention API changes or additions, and significant bugfixes. Fixed error message when an invalid color is specified does not sound very noteworthy, especially since most users will probably only encounter the error message once during development of their application.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Throw error on incorrect type in Image.putpixel
2 participants