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>
This commit is contained in:
Andrew Glick
2022-07-04 01:46:03 -05:00
committed by GitHub
parent f7ff6239ff
commit 0367fc94d9

View File

@@ -22,7 +22,10 @@ _Box: TypeAlias = tuple[int, int, int, int]
_ConversionMatrix: TypeAlias = Union[
tuple[float, float, float, float], tuple[float, float, float, float, float, float, float, float, float, float, float, float],
]
_Color: TypeAlias = float | tuple[float, ...]
# `str` values are only accepted if mode="RGB" for an `Image` object
# `float` values are only accepted for certain modes such as "F"
# See https://pillow.readthedocs.io/en/stable/reference/Image.html#PIL.Image.new
_Color: TypeAlias = Union[int, tuple[int], tuple[int, int, int], tuple[int, int, int, int], str, float, tuple[float]]
class _Writeable(SupportsWrite[bytes], Protocol):
def seek(self, __offset: int) -> Any: ...
@@ -220,7 +223,7 @@ class Image:
class ImagePointHandler: ...
class ImageTransformHandler: ...
def new(mode: _Mode, size: tuple[int, int], color: float | tuple[float, ...] | str = ...) -> Image: ...
def new(mode: _Mode, size: tuple[int, int], color: _Color = ...) -> Image: ...
def frombytes(mode: _Mode, size: tuple[int, int], data, decoder_name: str = ..., *args) -> Image: ...
def frombuffer(mode: _Mode, size: tuple[int, int], data, decoder_name: str = ..., *args) -> Image: ...
def fromarray(obj, mode: _Mode | None = ...) -> Image: ...