From 469c0aeeedd899e0f15cdc6ce737a356f719adcd Mon Sep 17 00:00:00 2001 From: Hugo Date: Mon, 1 Jul 2019 08:45:19 +0300 Subject: [PATCH 1/2] Deprecate Image.__del__ --- docs/deprecations.rst | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/docs/deprecations.rst b/docs/deprecations.rst index c21aea2b489..f00f3e31fa5 100644 --- a/docs/deprecations.rst +++ b/docs/deprecations.rst @@ -12,6 +12,29 @@ Deprecated features Below are features which are considered deprecated. Where appropriate, a ``DeprecationWarning`` is issued. +Image.__del__ +~~~~~~~~~~~~~ + +.. deprecated:: 6.1.0 + +Implicitly closing the image's underlying file in ``Image.__del__`` has been deprecated. +Use a context manager or call ``Image.close()`` instead to close the file in a +deterministic way. + +Deprecated: + +.. code-block:: python + + im = Image.open("hopper.png") + im.save("out.jpg") + +Use instead: + +.. code-block:: python + + with Image.open("hopper.png") as im: + im.save("out.jpg") + Python 2.7 ~~~~~~~~~~ From c15383695b4a1c477604425b00ae11617235b998 Mon Sep 17 00:00:00 2001 From: Hugo Date: Mon, 1 Jul 2019 09:55:54 +0300 Subject: [PATCH 2/2] Deprecate Image.__del__ --- docs/releasenotes/6.1.0.rst | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/docs/releasenotes/6.1.0.rst b/docs/releasenotes/6.1.0.rst index 851dcb2d0a4..ffe0aacf0b7 100644 --- a/docs/releasenotes/6.1.0.rst +++ b/docs/releasenotes/6.1.0.rst @@ -1,6 +1,32 @@ 6.1.0 ----- +Deprecations +============ + +Image.__del__ +^^^^^^^^^^^^^ + +.. deprecated:: 6.1.0 + +Implicitly closing the image's underlying file in ``Image.__del__`` has been deprecated. +Use a context manager or call ``Image.close()`` instead to close the file in a +deterministic way. + +Deprecated: + +.. code-block:: python + + im = Image.open("hopper.png") + im.save("out.jpg") + +Use instead: + +.. code-block:: python + + with Image.open("hopper.png") as im: + im.save("out.jpg") + API Additions =============