Conversation
| try: | ||
| fp = sys.stdout.buffer | ||
| except AttributeError: | ||
| fp = sys.stdout |
There was a problem hiding this comment.
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.
These ignores 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.
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
| :show-inheritance: | ||
| .. autoclass:: PIL.Image.ImagePointHandler | ||
| .. autoclass:: PIL.Image.ImageTransformHandler | ||
| .. autoclass:: PIL.Image._E |
There was a problem hiding this comment.
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.
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.
For a user-facing class, can we give it a description or a better name?
There was a problem hiding this comment.
I've added a description, and deprecated it in favour of a new name, ImagePointTransform.
No description provided.