mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-02-05 14:10:52 +03:00
Added type hints
This commit is contained in:
parent
1187777c5b
commit
741da90906
|
@ -514,22 +514,32 @@ class TestImage:
|
||||||
im = hopper()
|
im = hopper()
|
||||||
im.save(temp_file, convert_mode=True)
|
im.save(temp_file, convert_mode=True)
|
||||||
|
|
||||||
def test_convert_mode(self) -> None:
|
@pytest.mark.parametrize(
|
||||||
for mode, modes in [["P", []], ["P", ["P"]]]: # no modes, same mode
|
"mode, modes",
|
||||||
im = Image.new(mode, (100, 100))
|
(
|
||||||
assert im._convert_mode(modes) is None
|
("P", ["RGB"]),
|
||||||
|
("P", ["L"]), # converting to a non-preferred mode
|
||||||
for mode, modes in [
|
("LA", ["P"]),
|
||||||
["P", ["RGB"]],
|
("I", ["L"]),
|
||||||
["P", ["L"]], # converting to a non-preferred mode
|
("RGB", ["L"]),
|
||||||
["LA", ["P"]],
|
("RGB", ["CMYK"]),
|
||||||
["I", ["L"]],
|
),
|
||||||
["RGB", ["L"]],
|
)
|
||||||
["RGB", ["CMYK"]],
|
def test_convert_mode(self, mode: str, modes: list[str]) -> None:
|
||||||
]:
|
|
||||||
im = Image.new(mode, (100, 100))
|
im = Image.new(mode, (100, 100))
|
||||||
assert im._convert_mode(modes) is not None
|
assert im._convert_mode(modes) is not None
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"mode, modes",
|
||||||
|
(
|
||||||
|
("P", []), # no mode
|
||||||
|
("P", ["P"]), # same mode
|
||||||
|
),
|
||||||
|
)
|
||||||
|
def test_convert_mode_noop(self, mode: str, modes: list[str]) -> None:
|
||||||
|
im = Image.new(mode, (100, 100))
|
||||||
|
assert im._convert_mode(modes) is None
|
||||||
|
|
||||||
def test_effect_mandelbrot(self) -> None:
|
def test_effect_mandelbrot(self) -> None:
|
||||||
# Arrange
|
# Arrange
|
||||||
size = (512, 512)
|
size = (512, 512)
|
||||||
|
|
|
@ -1181,7 +1181,7 @@ def getdata(
|
||||||
return fp.data
|
return fp.data
|
||||||
|
|
||||||
|
|
||||||
def _supported_modes():
|
def _supported_modes() -> list[str]:
|
||||||
return ["RGB", "RGBA", "P", "I", "F", "LA", "L", "1"]
|
return ["RGB", "RGBA", "P", "I", "F", "LA", "L", "1"]
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -2618,9 +2618,11 @@ class Image:
|
||||||
if open_fp:
|
if open_fp:
|
||||||
fp.close()
|
fp.close()
|
||||||
|
|
||||||
def _convert_mode(self, modes, params={}):
|
def _convert_mode(
|
||||||
|
self, modes: list[str], params: dict[str, Any] = {}
|
||||||
|
) -> Image | None:
|
||||||
if not modes or self.mode in modes:
|
if not modes or self.mode in modes:
|
||||||
return
|
return None
|
||||||
if self.mode == "P":
|
if self.mode == "P":
|
||||||
preferred_modes = []
|
preferred_modes = []
|
||||||
if "A" in self.im.getpalettemode():
|
if "A" in self.im.getpalettemode():
|
||||||
|
@ -2674,6 +2676,8 @@ class Image:
|
||||||
elif new_mode:
|
elif new_mode:
|
||||||
return self.convert(new_mode)
|
return self.convert(new_mode)
|
||||||
|
|
||||||
|
return None
|
||||||
|
|
||||||
def seek(self, frame: int) -> None:
|
def seek(self, frame: int) -> None:
|
||||||
"""
|
"""
|
||||||
Seeks to the given frame in this sequence file. If you seek
|
Seeks to the given frame in this sequence file. If you seek
|
||||||
|
|
|
@ -891,7 +891,7 @@ def jpeg_factory(
|
||||||
return im
|
return im
|
||||||
|
|
||||||
|
|
||||||
def _supported_modes():
|
def _supported_modes() -> list[str]:
|
||||||
return ["RGB", "CMYK", "YCbCr", "RGBX", "L", "1"]
|
return ["RGB", "CMYK", "YCbCr", "RGBX", "L", "1"]
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1532,7 +1532,7 @@ def getchunks(im: Image.Image, **params: Any) -> list[tuple[bytes, bytes, bytes]
|
||||||
return chunks
|
return chunks
|
||||||
|
|
||||||
|
|
||||||
def _supported_modes():
|
def _supported_modes() -> list[str]:
|
||||||
return ["RGB", "RGBA", "P", "I", "LA", "L", "1"]
|
return ["RGB", "RGBA", "P", "I", "LA", "L", "1"]
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -314,7 +314,7 @@ def _save(im: Image.Image, fp: IO[bytes], filename: str | bytes) -> None:
|
||||||
fp.write(data)
|
fp.write(data)
|
||||||
|
|
||||||
|
|
||||||
def _supported_modes():
|
def _supported_modes() -> list[str]:
|
||||||
return [
|
return [
|
||||||
"RGB",
|
"RGB",
|
||||||
"RGBA",
|
"RGBA",
|
||||||
|
|
Loading…
Reference in New Issue
Block a user