mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-11-10 19:56:47 +03:00
Deprecate isImageType
This commit is contained in:
parent
be01d536c6
commit
e0845f06d8
|
@ -1117,6 +1117,10 @@ class TestImage:
|
||||||
assert len(caplog.records) == 0
|
assert len(caplog.records) == 0
|
||||||
assert im.fp is None
|
assert im.fp is None
|
||||||
|
|
||||||
|
def test_deprecation(self) -> None:
|
||||||
|
with pytest.warns(DeprecationWarning):
|
||||||
|
assert not Image.isImageType(None)
|
||||||
|
|
||||||
|
|
||||||
class TestImageBytes:
|
class TestImageBytes:
|
||||||
@pytest.mark.parametrize("mode", Image.MODES + ["BGR;15", "BGR;16", "BGR;24"])
|
@pytest.mark.parametrize("mode", Image.MODES + ["BGR;15", "BGR;16", "BGR;24"])
|
||||||
|
|
|
@ -122,6 +122,14 @@ vulnerability introduced in FreeType 2.6 (:cve:`2020-15999`).
|
||||||
|
|
||||||
.. _2.10.4: https://sourceforge.net/projects/freetype/files/freetype2/2.10.4/
|
.. _2.10.4: https://sourceforge.net/projects/freetype/files/freetype2/2.10.4/
|
||||||
|
|
||||||
|
Image isImageType()
|
||||||
|
^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
.. deprecated:: 11.0.0
|
||||||
|
|
||||||
|
``Image.isImageType(im)`` has been deprecated. Use ``isinstance(im, Image.Image)``
|
||||||
|
instead.
|
||||||
|
|
||||||
ImageMath.lambda_eval and ImageMath.unsafe_eval options parameter
|
ImageMath.lambda_eval and ImageMath.unsafe_eval options parameter
|
||||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
|
|
@ -61,6 +61,14 @@ vulnerability introduced in FreeType 2.6 (:cve:`2020-15999`).
|
||||||
|
|
||||||
.. _2.10.4: https://sourceforge.net/projects/freetype/files/freetype2/2.10.4/
|
.. _2.10.4: https://sourceforge.net/projects/freetype/files/freetype2/2.10.4/
|
||||||
|
|
||||||
|
Image isImageType()
|
||||||
|
^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
.. deprecated:: 11.0.0
|
||||||
|
|
||||||
|
``Image.isImageType(im)`` has been deprecated. Use ``isinstance(im, Image.Image)``
|
||||||
|
instead.
|
||||||
|
|
||||||
ImageMath.lambda_eval and ImageMath.unsafe_eval options parameter
|
ImageMath.lambda_eval and ImageMath.unsafe_eval options parameter
|
||||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
|
|
@ -133,6 +133,7 @@ def isImageType(t: Any) -> TypeGuard[Image]:
|
||||||
:param t: object to check if it's an image
|
:param t: object to check if it's an image
|
||||||
:returns: True if the object is an image
|
:returns: True if the object is an image
|
||||||
"""
|
"""
|
||||||
|
deprecate("Image.isImageType(im)", 12, "isinstance(im, Image.Image)")
|
||||||
return hasattr(t, "im")
|
return hasattr(t, "im")
|
||||||
|
|
||||||
|
|
||||||
|
@ -1823,23 +1824,22 @@ class Image:
|
||||||
:param mask: An optional mask image.
|
:param mask: An optional mask image.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if isImageType(box):
|
if isinstance(box, Image):
|
||||||
if mask is not None:
|
if mask is not None:
|
||||||
msg = "If using second argument as mask, third argument must be None"
|
msg = "If using second argument as mask, third argument must be None"
|
||||||
raise ValueError(msg)
|
raise ValueError(msg)
|
||||||
# abbreviated paste(im, mask) syntax
|
# abbreviated paste(im, mask) syntax
|
||||||
mask = box
|
mask = box
|
||||||
box = None
|
box = None
|
||||||
assert not isinstance(box, Image)
|
|
||||||
|
|
||||||
if box is None:
|
if box is None:
|
||||||
box = (0, 0)
|
box = (0, 0)
|
||||||
|
|
||||||
if len(box) == 2:
|
if len(box) == 2:
|
||||||
# upper left corner given; get size from image or mask
|
# upper left corner given; get size from image or mask
|
||||||
if isImageType(im):
|
if isinstance(im, Image):
|
||||||
size = im.size
|
size = im.size
|
||||||
elif isImageType(mask):
|
elif isinstance(mask, Image):
|
||||||
size = mask.size
|
size = mask.size
|
||||||
else:
|
else:
|
||||||
# FIXME: use self.size here?
|
# FIXME: use self.size here?
|
||||||
|
@ -1852,17 +1852,15 @@ class Image:
|
||||||
from . import ImageColor
|
from . import ImageColor
|
||||||
|
|
||||||
source = ImageColor.getcolor(im, self.mode)
|
source = ImageColor.getcolor(im, self.mode)
|
||||||
elif isImageType(im):
|
elif isinstance(im, Image):
|
||||||
im.load()
|
im.load()
|
||||||
if self.mode != im.mode:
|
if self.mode != im.mode:
|
||||||
if self.mode != "RGB" or im.mode not in ("LA", "RGBA", "RGBa"):
|
if self.mode != "RGB" or im.mode not in ("LA", "RGBA", "RGBa"):
|
||||||
# should use an adapter for this!
|
# should use an adapter for this!
|
||||||
im = im.convert(self.mode)
|
im = im.convert(self.mode)
|
||||||
source = im.im
|
source = im.im
|
||||||
elif isinstance(im, tuple):
|
|
||||||
source = im
|
|
||||||
else:
|
else:
|
||||||
source = cast(float, im)
|
source = im
|
||||||
|
|
||||||
self._ensure_mutable()
|
self._ensure_mutable()
|
||||||
|
|
||||||
|
@ -2023,7 +2021,7 @@ class Image:
|
||||||
else:
|
else:
|
||||||
band = 3
|
band = 3
|
||||||
|
|
||||||
if isImageType(alpha):
|
if isinstance(alpha, Image):
|
||||||
# alpha layer
|
# alpha layer
|
||||||
if alpha.mode not in ("1", "L"):
|
if alpha.mode not in ("1", "L"):
|
||||||
msg = "illegal image mode"
|
msg = "illegal image mode"
|
||||||
|
@ -2033,7 +2031,6 @@ class Image:
|
||||||
alpha = alpha.convert("L")
|
alpha = alpha.convert("L")
|
||||||
else:
|
else:
|
||||||
# constant alpha
|
# constant alpha
|
||||||
alpha = cast(int, alpha) # see python/typing#1013
|
|
||||||
try:
|
try:
|
||||||
self.im.fillband(band, alpha)
|
self.im.fillband(band, alpha)
|
||||||
except (AttributeError, ValueError):
|
except (AttributeError, ValueError):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user