-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Added type hints #8319
Added type hints #8319
Conversation
try: | ||
fp = sys.stdout.buffer | ||
except AttributeError: | ||
fp = sys.stdout |
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.
When mypy looks at sys.stdout
here, it says
expression has type "Union[TextIO, Any]"
I think #5437 misinterpreted the docs, and that really, sys.stdout
will not accept the bytes that we are sending.
https://docs.python.org/3/library/sys.html#sys.stdout
be aware that the standard streams may be replaced with file-like objects like io.StringIO which do not support the buffer attribute.
return self._new(self.im.point_transform(scale, offset)) | ||
# for other modes, convert the function to a table | ||
flatLut = [lut(i) for i in range(256)] * self.im.bands | ||
flatLut = [lut(i) for i in range(256)] * self.im.bands # type: ignore[arg-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.
These ignore
s are to prevent
src/PIL/Image.py:1939: error: Argument 1 to "_getscaleoffset" has incompatible type "Union[Callable[[int], float], Callable[[_E], Union[_E, float]]]";
expected "Callable[[_E], Union[_E, float]]" [arg-type]
scale, offset = _getscaleoffset(lut)
^~~
src/PIL/Image.py:1942: error: Argument 1 has incompatible type "int"; expected "_E" [arg-type]
flatLut = [lut(i) for i in range(256)] * self.im.bands
It is because Callable[[_E], _E | float]
is for the first line, and Callable[[int], float]
is for the second line, and I don't think there's an elegant way to differentiate the values.
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's an underscore name so "private" and we can rename it without deprecation. I see very little use on GitHub:
But I don't mind being cautious and deprecating first if you prefer.
330e341
to
dab3346
Compare
docs/reference/Image.rst
Outdated
@@ -363,6 +363,7 @@ Classes | |||
:show-inheritance: | |||
.. autoclass:: PIL.Image.ImagePointHandler | |||
.. autoclass:: PIL.Image.ImageTransformHandler | |||
.. autoclass:: PIL.Image._E |
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.
Do we want this "empty" internal class in the docs?

https://pillow--8319.org.readthedocs.build/en/8319/reference/Image.html#PIL.Image._E
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's referenced from the type hint of https://pillow--8319.org.readthedocs.build/en/8319/reference/Image.html#PIL.Image.Image.point
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.
For a user-facing class, can we give it a description or a better name?
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.
I've added a description, and deprecated it in favour of a new name, ImagePointTransform
.
No description provided.