Skip to content

Commit e27d7a6

Browse files
committed
Changed has_transparency_data() to property
1 parent 1c30809 commit e27d7a6

File tree

4 files changed

+8
-7
lines changed

4 files changed

+8
-7
lines changed

Tests/test_image.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -909,27 +909,27 @@ def test_zero_tobytes(self, size):
909909
def test_has_transparency_data(self):
910910
for mode in ("1", "L", "P", "RGB"):
911911
im = Image.new(mode, (1, 1))
912-
assert not im.has_transparency_data()
912+
assert not im.has_transparency_data
913913

914914
for mode in ("LA", "La", "PA", "RGBA", "RGBa"):
915915
im = Image.new(mode, (1, 1))
916-
assert im.has_transparency_data()
916+
assert im.has_transparency_data
917917

918918
# P mode with "transparency" info
919919
with Image.open("Tests/images/first_frame_transparency.gif") as im:
920920
assert "transparency" in im.info
921-
assert im.has_transparency_data()
921+
assert im.has_transparency_data
922922

923923
# RGB mode with "transparency" info
924924
with Image.open("Tests/images/rgb_trns.png") as im:
925925
assert "transparency" in im.info
926-
assert im.has_transparency_data()
926+
assert im.has_transparency_data
927927

928928
# P mode with RGBA palette
929929
im = Image.new("RGBA", (1, 1)).convert("P")
930930
assert im.mode == "P"
931931
assert im.palette.mode == "RGBA"
932-
assert im.has_transparency_data()
932+
assert im.has_transparency_data
933933

934934
def test_apply_transparency(self):
935935
im = Image.new("P", (1, 1))

docs/reference/Image.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ This helps to get the bounding box coordinates of the input image::
195195
.. automethod:: PIL.Image.Image.getpalette
196196
.. automethod:: PIL.Image.Image.getpixel
197197
.. automethod:: PIL.Image.Image.getprojection
198-
.. automethod:: PIL.Image.Image.has_transparency_data
198+
.. autoproperty:: PIL.Image.Image.has_transparency_data
199199
.. automethod:: PIL.Image.Image.histogram
200200
.. automethod:: PIL.Image.Image.paste
201201
.. automethod:: PIL.Image.Image.point

src/PIL/Image.py

+1
Original file line numberDiff line numberDiff line change
@@ -1531,6 +1531,7 @@ def getpalette(self, rawmode="RGB"):
15311531
rawmode = mode
15321532
return list(self.im.getpalette(mode, rawmode))
15331533

1534+
@property
15341535
def has_transparency_data(self) -> bool:
15351536
"""
15361537
Determine if an image has transparency data, whether in the form of an

src/PIL/WebPImagePlugin.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ def _save(im, fp, filename):
332332
exact = 1 if im.encoderinfo.get("exact") else 0
333333

334334
if im.mode not in _VALID_WEBP_LEGACY_MODES:
335-
im = im.convert("RGBA" if im.has_transparency_data() else "RGB")
335+
im = im.convert("RGBA" if im.has_transparency_data else "RGB")
336336

337337
data = _webp.WebPEncode(
338338
im.tobytes(),

0 commit comments

Comments
 (0)