From faea2bbecd92840b76d1016c9c69c57a739580c7 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Tue, 26 Sep 2023 19:59:53 +1000 Subject: [PATCH] Changed has_transparency_data() to property --- Tests/test_image.py | 10 +++++----- docs/reference/Image.rst | 2 +- src/PIL/Image.py | 1 + 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/Tests/test_image.py b/Tests/test_image.py index 487035a3ef9..b9c57770c70 100644 --- a/Tests/test_image.py +++ b/Tests/test_image.py @@ -909,27 +909,27 @@ def test_zero_tobytes(self, size): def test_has_transparency_data(self): for mode in ("1", "L", "P", "RGB"): im = Image.new(mode, (1, 1)) - assert not im.has_transparency_data() + assert not im.has_transparency_data for mode in ("LA", "La", "PA", "RGBA", "RGBa"): im = Image.new(mode, (1, 1)) - assert im.has_transparency_data() + assert im.has_transparency_data # P mode with "transparency" info with Image.open("Tests/images/first_frame_transparency.gif") as im: assert "transparency" in im.info - assert im.has_transparency_data() + assert im.has_transparency_data # RGB mode with "transparency" info with Image.open("Tests/images/rgb_trns.png") as im: assert "transparency" in im.info - assert im.has_transparency_data() + assert im.has_transparency_data # P mode with RGBA palette im = Image.new("RGBA", (1, 1)).convert("P") assert im.mode == "P" assert im.palette.mode == "RGBA" - assert im.has_transparency_data() + assert im.has_transparency_data def test_apply_transparency(self): im = Image.new("P", (1, 1)) diff --git a/docs/reference/Image.rst b/docs/reference/Image.rst index ae8f923cb7a..e356469b673 100644 --- a/docs/reference/Image.rst +++ b/docs/reference/Image.rst @@ -195,7 +195,7 @@ This helps to get the bounding box coordinates of the input image:: .. automethod:: PIL.Image.Image.getpalette .. automethod:: PIL.Image.Image.getpixel .. automethod:: PIL.Image.Image.getprojection -.. automethod:: PIL.Image.Image.has_transparency_data +.. autoproperty:: PIL.Image.Image.has_transparency_data .. automethod:: PIL.Image.Image.histogram .. automethod:: PIL.Image.Image.paste .. automethod:: PIL.Image.Image.point diff --git a/src/PIL/Image.py b/src/PIL/Image.py index 842e5db56ea..244d2e43520 100644 --- a/src/PIL/Image.py +++ b/src/PIL/Image.py @@ -1531,6 +1531,7 @@ def getpalette(self, rawmode="RGB"): rawmode = mode return list(self.im.getpalette(mode, rawmode)) + @property def has_transparency_data(self) -> bool: """ Determine if an image has transparency data, whether in the form of an