diff --git a/PIL/Image.py b/PIL/Image.py index 861599bf7a4..c08a1252dbd 100644 --- a/PIL/Image.py +++ b/PIL/Image.py @@ -681,18 +681,9 @@ def tobytes(self, encoder_name="raw", *args): return b"".join(data) - # Declare tostring as alias to tobytes def tostring(self, *args, **kw): - """Deprecated alias to tobytes. - - .. deprecated:: 2.0 - """ - warnings.warn( - 'tostring() is deprecated. Please call tobytes() instead.', - DeprecationWarning, - stacklevel=2, - ) - return self.tobytes(*args, **kw) + raise Exception("tostring() has been removed. " + + "Please call tobytes() instead.") def tobitmap(self, name="image"): """ @@ -742,14 +733,8 @@ def frombytes(self, data, decoder_name="raw", *args): raise ValueError("cannot decode image data") def fromstring(self, *args, **kw): - """Deprecated alias to frombytes. - - .. deprecated:: 2.0 - """ - warnings.warn( - 'fromstring() is deprecated. Please call frombytes() instead.', - DeprecationWarning) - return self.frombytes(*args, **kw) + raise Exception("fromstring() has been removed. " + + "Please call frombytes() instead.") def load(self): """ @@ -1248,27 +1233,8 @@ def histogram(self, mask=None, extrema=None): return self.im.histogram() def offset(self, xoffset, yoffset=None): - """ - .. deprecated:: 2.0 - - .. note:: New code should use :py:func:`PIL.ImageChops.offset`. - - Returns a copy of the image where the data has been offset by the given - distances. Data wraps around the edges. If **yoffset** is omitted, it - is assumed to be equal to **xoffset**. - - :param xoffset: The horizontal distance. - :param yoffset: The vertical distance. If omitted, both - distances are set to the same value. - :returns: An :py:class:`~PIL.Image.Image` object. - """ - if warnings: - warnings.warn( - "'offset' is deprecated; use 'ImageChops.offset' instead", - DeprecationWarning, stacklevel=2 - ) - from PIL import ImageChops - return ImageChops.offset(self, xoffset, yoffset) + raise Exception("offset() has been removed. " + + "Please call ImageChops.offset() instead.") def paste(self, im, box=None, mask=None): """ @@ -2081,16 +2047,8 @@ def frombytes(mode, size, data, decoder_name="raw", *args): def fromstring(*args, **kw): - """Deprecated alias to frombytes. - - .. deprecated:: 2.0 - """ - warnings.warn( - 'fromstring() is deprecated. Please call frombytes() instead.', - DeprecationWarning, - stacklevel=2 - ) - return frombytes(*args, **kw) + raise Exception("fromstring() has been removed. " + + "Please call frombytes() instead.") def frombuffer(mode, size, data, decoder_name="raw", *args): diff --git a/PIL/ImageDraw.py b/PIL/ImageDraw.py index 2afe937144b..9e154f236e3 100644 --- a/PIL/ImageDraw.py +++ b/PIL/ImageDraw.py @@ -90,38 +90,18 @@ def __init__(self, im, mode=None): self.fill = 0 self.font = None - ## - # Set the default pen color. - def setink(self, ink): - # compatibility - if warnings: - warnings.warn( - "'setink' is deprecated; use keyword arguments instead", - DeprecationWarning, stacklevel=2 - ) - if isStringType(ink): - ink = ImageColor.getcolor(ink, self.mode) - if self.palette and not isinstance(ink, numbers.Number): - ink = self.palette.getcolor(ink) - self.ink = self.draw.draw_ink(ink, self.mode) - - ## - # Set the default background color. + raise Exception("setink() has been removed. " + + "Please use keyword arguments instead.") def setfill(self, onoff): - # compatibility - if warnings: - warnings.warn( - "'setfill' is deprecated; use keyword arguments instead", - DeprecationWarning, stacklevel=2 - ) - self.fill = onoff - - ## - # Set the default font. + raise Exception("setfill() has been removed. " + + "Please use keyword arguments instead.") def setfont(self, font): + if warnings: + warnings.warn("setfont() is deprecated. " + + "Please set the attribute directly instead.") # compatibility self.font = font diff --git a/PIL/ImageFileIO.py b/PIL/ImageFileIO.py deleted file mode 100644 index e57d3f43ecf..00000000000 --- a/PIL/ImageFileIO.py +++ /dev/null @@ -1,40 +0,0 @@ -# -# The Python Imaging Library. -# $Id$ -# -# kludge to get basic ImageFileIO functionality -# -# History: -# 1998-08-06 fl Recreated -# -# Copyright (c) Secret Labs AB 1998-2002. -# -# See the README file for information on usage and redistribution. -# -""" -The **ImageFileIO** module can be used to read an image from a -socket, or any other stream device. - -Deprecated. New code should use the :class:`PIL.ImageFile.Parser` -class in the :mod:`PIL.ImageFile` module instead. - -.. seealso:: modules :class:`PIL.ImageFile.Parser` -""" - -from io import BytesIO - - -class ImageFileIO(BytesIO): - def __init__(self, fp): - """ - Adds buffering to a stream file object, in order to - provide **seek** and **tell** methods required - by the :func:`PIL.Image.Image.open` method. The stream object must - implement **read** and **close** methods. - - :param fp: Stream file handle. - - .. seealso:: modules :func:`PIL.Image.open` - """ - data = fp.read() - BytesIO.__init__(self, data) diff --git a/PIL/ImageFont.py b/PIL/ImageFont.py index e3fb6f503ef..fce44caff10 100644 --- a/PIL/ImageFont.py +++ b/PIL/ImageFont.py @@ -121,15 +121,8 @@ def _load_pilfont_data(self, file, image): class FreeTypeFont(object): "FreeType font wrapper (requires _imagingft service)" - def __init__(self, font=None, size=10, index=0, encoding="", file=None): + def __init__(self, font=None, size=10, index=0, encoding=""): # FIXME: use service provider instead - if file: - if warnings: - warnings.warn( - 'file parameter deprecated, ' - 'please use font parameter instead.', - DeprecationWarning) - font = file self.path = font self.size = size @@ -171,7 +164,7 @@ def font_variant(self, font=None, size=None, index=None, encoding=None): using any specified arguments to override the settings. Parameters are identical to the parameters used to initialize this - object, minus the deprecated 'file' argument. + object. :return: A FreeTypeFont object. """ @@ -225,7 +218,7 @@ def load(filename): return f -def truetype(font=None, size=10, index=0, encoding="", filename=None): +def truetype(font=None, size=10, index=0, encoding=""): """ Load a TrueType or OpenType font file, and create a font object. This function loads a font object from the given file, and creates @@ -243,19 +236,10 @@ def truetype(font=None, size=10, index=0, encoding="", filename=None): Symbol), "ADOB" (Adobe Standard), "ADBE" (Adobe Expert), and "armn" (Apple Roman). See the FreeType documentation for more information. - :param filename: Deprecated. Please use font instead. :return: A font object. :exception IOError: If the file could not be read. """ - if filename: - if warnings: - warnings.warn( - 'filename parameter deprecated, ' - 'please use font parameter instead.', - DeprecationWarning) - font = filename - try: return FreeTypeFont(font, size, index, encoding) except IOError: diff --git a/PIL/ImagePalette.py b/PIL/ImagePalette.py index 5aabaa13839..4f6845243d6 100644 --- a/PIL/ImagePalette.py +++ b/PIL/ImagePalette.py @@ -17,7 +17,6 @@ # import array -import warnings from PIL import ImageColor @@ -68,7 +67,6 @@ def tobytes(self): return self.palette arr = array.array("B", self.palette) if hasattr(arr, 'tobytes'): - # py3k has a tobytes, tostring is deprecated. return arr.tobytes() return arr.tostring() @@ -137,26 +135,6 @@ def raw(rawmode, data): # -------------------------------------------------------------------- # Factories -def _make_linear_lut(black, white): - warnings.warn( - '_make_linear_lut() is deprecated. ' - 'Please call make_linear_lut() instead.', - DeprecationWarning, - stacklevel=2 - ) - return make_linear_lut(black, white) - - -def _make_gamma_lut(exp): - warnings.warn( - '_make_gamma_lut() is deprecated. ' - 'Please call make_gamma_lut() instead.', - DeprecationWarning, - stacklevel=2 - ) - return make_gamma_lut(exp) - - def make_linear_lut(black, white): lut = [] if black == 0: diff --git a/PIL/ImageWin.py b/PIL/ImageWin.py index bcb54bc3eaa..58894d6041e 100644 --- a/PIL/ImageWin.py +++ b/PIL/ImageWin.py @@ -17,7 +17,6 @@ # See the README file for information on usage and redistribution. # -import warnings from PIL import Image @@ -183,24 +182,13 @@ def tobytes(self): """ return self.image.tobytes() - ## - # Deprecated aliases to frombytes & tobytes. - def fromstring(self, *args, **kw): - warnings.warn( - 'fromstring() is deprecated. Please call frombytes() instead.', - DeprecationWarning, - stacklevel=2 - ) - return self.frombytes(*args, **kw) - - def tostring(self): - warnings.warn( - 'tostring() is deprecated. Please call tobytes() instead.', - DeprecationWarning, - stacklevel=2 - ) - return self.tobytes() + raise Exception("fromstring() has been removed. " + + "Please use frombytes() instead.") + + def tostring(self, *args, **kw): + raise Exception("tostring() has been removed. " + + "Please use tobytes() instead.") ## diff --git a/Tests/test_image_offset.py b/Tests/test_image_offset.py deleted file mode 100644 index e5fe0bf472c..00000000000 --- a/Tests/test_image_offset.py +++ /dev/null @@ -1,25 +0,0 @@ -from helper import unittest, PillowTestCase, hopper - - -class TestImageOffset(PillowTestCase): - - def test_offset(self): - - im1 = hopper() - - im2 = self.assert_warning(DeprecationWarning, lambda: im1.offset(10)) - self.assertEqual(im1.getpixel((0, 0)), im2.getpixel((10, 10))) - - im2 = self.assert_warning( - DeprecationWarning, lambda: im1.offset(10, 20)) - self.assertEqual(im1.getpixel((0, 0)), im2.getpixel((10, 20))) - - im2 = self.assert_warning( - DeprecationWarning, lambda: im1.offset(20, 20)) - self.assertEqual(im1.getpixel((0, 0)), im2.getpixel((20, 20))) - - -if __name__ == '__main__': - unittest.main() - -# End of file diff --git a/Tests/test_imagedraw.py b/Tests/test_imagedraw.py index 8036776168a..3074fd7faba 100644 --- a/Tests/test_imagedraw.py +++ b/Tests/test_imagedraw.py @@ -44,13 +44,13 @@ def test_sanity(self): draw.polygon(list(range(100))) draw.rectangle(list(range(4))) - def test_deprecated(self): - im = hopper().copy() + def test_removed_methods(self): + im = hopper() draw = ImageDraw.Draw(im) - self.assert_warning(DeprecationWarning, lambda: draw.setink(0)) - self.assert_warning(DeprecationWarning, lambda: draw.setfill(0)) + self.assertRaises(Exception, lambda: draw.setink(0)) + self.assertRaises(Exception, lambda: draw.setfill(0)) def test_mode_mismatch(self): im = hopper("RGB").copy() diff --git a/Tests/test_imagefileio.py b/Tests/test_imagefileio.py deleted file mode 100644 index b0617843708..00000000000 --- a/Tests/test_imagefileio.py +++ /dev/null @@ -1,33 +0,0 @@ -from helper import unittest, PillowTestCase, hopper, tostring - -from PIL import Image -from PIL import ImageFileIO - - -class TestImageFileIo(PillowTestCase): - - def test_fileio(self): - - class DumbFile(object): - def __init__(self, data): - self.data = data - - def read(self, bytes=None): - assert(bytes is None) - return self.data - - def close(self): - pass - - im1 = hopper() - - io = ImageFileIO.ImageFileIO(DumbFile(tostring(im1, "PPM"))) - - im2 = Image.open(io) - self.assert_image_equal(im1, im2) - - -if __name__ == '__main__': - unittest.main() - -# End of file diff --git a/Tests/test_imagefont.py b/Tests/test_imagefont.py index 1fd70b3d853..dd223446756 100644 --- a/Tests/test_imagefont.py +++ b/Tests/test_imagefont.py @@ -88,11 +88,6 @@ def test_font_with_open_file(self): self._render(f) self._clean() - def test_font_old_parameters(self): - self.assert_warning( - DeprecationWarning, - lambda: ImageFont.truetype(filename=FONT_PATH, size=FONT_SIZE)) - def _render(self, font): txt = "Hello World!" ttf = ImageFont.truetype(font, FONT_SIZE) @@ -228,11 +223,11 @@ def test_rotated_transposed_font(self): font, orientation=orientation) # Original font - draw.setfont(font) + draw.font = font box_size_a = draw.textsize(word) # Rotated font - draw.setfont(transposed_font) + draw.font = transposed_font box_size_b = draw.textsize(word) # Check (w,h) of box a is (h,w) of box b @@ -250,11 +245,11 @@ def test_unrotated_transposed_font(self): font, orientation=orientation) # Original font - draw.setfont(font) + draw.font = font box_size_a = draw.textsize(word) # Rotated font - draw.setfont(transposed_font) + draw.font = transposed_font box_size_b = draw.textsize(word) # Check boxes a and b are same size diff --git a/Tests/test_imagepalette.py b/Tests/test_imagepalette.py index 707ab4080cf..a175f70852b 100644 --- a/Tests/test_imagepalette.py +++ b/Tests/test_imagepalette.py @@ -90,27 +90,6 @@ def test_make_gamma_lut(self): self.assertEqual(lut[191], 60) self.assertEqual(lut[255], 255) - def test_private_make_linear_lut_warning(self): - # Arrange - from PIL.ImagePalette import _make_linear_lut - black = 0 - white = 255 - - # Act / Assert - self.assert_warning( - DeprecationWarning, - lambda: _make_linear_lut(black, white)) - - def test_private_make_gamma_lut_warning(self): - # Arrange - from PIL.ImagePalette import _make_gamma_lut - exp = 5 - - # Act / Assert - self.assert_warning( - DeprecationWarning, - lambda: _make_gamma_lut(exp)) - def test_rawmode_valueerrors(self): # Arrange from PIL.ImagePalette import raw diff --git a/Tests/test_imagewin.py b/Tests/test_imagewin.py index 8a5bc125f04..14cc2c7e3a1 100644 --- a/Tests/test_imagewin.py +++ b/Tests/test_imagewin.py @@ -107,16 +107,14 @@ def test_dib_frombytes_tobytes_roundtrip(self): # Confirm they're the same self.assertEqual(dib1.tobytes(), dib2.tobytes()) - def test_dib_fromstring_tostring_deprecated(self): + def test_removed_methods(self): # Arrange im = hopper() dib = ImageWin.Dib(im) - test_buffer = dib.tobytes() # Act/Assert - self.assert_warning(DeprecationWarning, dib.tostring) - self.assert_warning(DeprecationWarning, - lambda: dib.fromstring(test_buffer)) + self.assertRaises(Exception, dib.tostring) + self.assertRaises(Exception, lambda: dib.fromstring(test_buffer)) if __name__ == '__main__': diff --git a/docs/PIL.rst b/docs/PIL.rst index 53a61872be0..c171b80b1fd 100644 --- a/docs/PIL.rst +++ b/docs/PIL.rst @@ -64,15 +64,6 @@ can be found here. .. intentionally skipped documenting this because it's deprecated -:mod:`ImageFileIO` Module -------------------------- - -.. automodule:: PIL.ImageFileIO - :members: - :undoc-members: - :show-inheritance: - - :mod:`ImageShow` Module ----------------------- diff --git a/docs/reference/ImageDraw.rst b/docs/reference/ImageDraw.rst index e030147e981..9a2a7a260b4 100644 --- a/docs/reference/ImageDraw.rst +++ b/docs/reference/ImageDraw.rst @@ -278,21 +278,6 @@ these methods. Do not mix the old and new calling conventions. :rtype: :py:class:`~PIL.ImageDraw.Draw` -.. py:method:: PIL.ImageDraw.Draw.setink(ink) - - .. deprecated:: 1.1.5 - - Sets the color to use for subsequent draw and fill operations. - -.. py:method:: PIL.ImageDraw.Draw.setfill(fill) - - .. deprecated:: 1.1.5 - - Sets the fill mode. - - If the mode is 0, subsequently drawn shapes (like polygons and rectangles) - are outlined. If the mode is 1, they are filled. - .. py:method:: PIL.ImageDraw.Draw.setfont(font) .. deprecated:: 1.1.5