Skip to content

Commit 0367fc9

Browse files
Antyospre-commit-ci[bot]AlexWaygood
authored
Improve_Color type alias of PIL.Image (#8210)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
1 parent f7ff623 commit 0367fc9

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

stubs/Pillow/PIL/Image.pyi

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ _Box: TypeAlias = tuple[int, int, int, int]
2222
_ConversionMatrix: TypeAlias = Union[
2323
tuple[float, float, float, float], tuple[float, float, float, float, float, float, float, float, float, float, float, float],
2424
]
25-
_Color: TypeAlias = float | tuple[float, ...]
25+
# `str` values are only accepted if mode="RGB" for an `Image` object
26+
# `float` values are only accepted for certain modes such as "F"
27+
# See https://pillow.readthedocs.io/en/stable/reference/Image.html#PIL.Image.new
28+
_Color: TypeAlias = Union[int, tuple[int], tuple[int, int, int], tuple[int, int, int, int], str, float, tuple[float]]
2629

2730
class _Writeable(SupportsWrite[bytes], Protocol):
2831
def seek(self, __offset: int) -> Any: ...
@@ -220,7 +223,7 @@ class Image:
220223
class ImagePointHandler: ...
221224
class ImageTransformHandler: ...
222225

223-
def new(mode: _Mode, size: tuple[int, int], color: float | tuple[float, ...] | str = ...) -> Image: ...
226+
def new(mode: _Mode, size: tuple[int, int], color: _Color = ...) -> Image: ...
224227
def frombytes(mode: _Mode, size: tuple[int, int], data, decoder_name: str = ..., *args) -> Image: ...
225228
def frombuffer(mode: _Mode, size: tuple[int, int], data, decoder_name: str = ..., *args) -> Image: ...
226229
def fromarray(obj, mode: _Mode | None = ...) -> Image: ...

0 commit comments

Comments
 (0)