Pillow/src/PIL
Jon Dufresne 4cd4adddc3 Improve handling of file resources
Follow Python's file object semantics. User code is responsible for
closing resources (usually through a context manager) in a deterministic
way.

To achieve this, remove __del__ functions. These functions used to
closed open file handlers in an attempt to silence Python
ResourceWarnings. However, using __del__ has the following drawbacks:

- __del__ isn't called until the object's reference count reaches 0.
  Therefore, resource handlers remain open or in use longer than
  necessary.

- The __del__ method isn't guaranteed to execute on system exit. See the
  Python documentation:

  https://docs.python.org/3/reference/datamodel.html#object.__del__

  > It is not guaranteed that __del__() methods are called for objects
  > that still exist when the interpreter exits.

- Exceptions that occur inside __del__ are ignored instead of raised.
  This has the potential of hiding bugs. This is also in the Python
  documentation:

  > Warning: Due to the precarious circumstances under which __del__()
  > methods are invoked, exceptions that occur during their execution
  > are ignored, and a warning is printed to sys.stderr instead.

Instead, always close resource handlers when they are no longer in use.
This will close the file handler at a specified point in the user's code
and not wait until the interpreter chooses to. It is always guaranteed
to run. And, if an exception occurs while closing the file handler, the
bug will not be ignored.

Now, when code receives a ResourceWarning, it will highlight an area
that is mishandling resources. It should not simply be silenced, but
fixed by closing resources with a context manager.

All warnings that were emitted during tests have been cleaned up. To
enable warnings, I passed the `-Wa` CLI option to Python. This exposed
some mishandling of resources in ImageFile.__init__() and
SpiderImagePlugin.loadImageSeries(), they too were fixed.
2019-10-12 08:27:17 -07:00
..
__init__.py Removed outdated VERSION comment 2019-10-03 20:54:55 +10:00
__main__.py Add __main__.py to output basic format and support information 2019-05-27 18:44:04 -07:00
_binary.py Introduce isort to automate import ordering and formatting 2019-07-06 16:11:35 -07:00
_tkinter_finder.py Format with Black 2019-06-10 18:22:46 +03:00
_util.py Format with Black 2019-06-10 18:22:46 +03:00
_version.py 7.0.0.dev0 version bump 2019-10-02 06:42:14 +10:00
BdfFontFile.py Introduce isort to automate import ordering and formatting 2019-07-06 16:11:35 -07:00
BlpImagePlugin.py Introduce isort to automate import ordering and formatting 2019-07-06 16:11:35 -07:00
BmpImagePlugin.py Simplified definition of values 2019-06-12 02:12:57 +10:00
BufrStubImagePlugin.py Format with Black 2019-06-10 18:22:46 +03:00
ContainerIO.py Format with Black 2019-06-10 18:22:46 +03:00
CurImagePlugin.py Introduce isort to automate import ordering and formatting 2019-07-06 16:11:35 -07:00
DcxImagePlugin.py Format with Black 2019-06-10 18:22:46 +03:00
DdsImagePlugin.py Introduce isort to automate import ordering and formatting 2019-07-06 16:11:35 -07:00
EpsImagePlugin.py Move several imports to the top-level of the file 2019-10-07 06:28:36 -07:00
ExifTags.py Format with Black 2019-06-10 18:22:46 +03:00
features.py Introduce isort to automate import ordering and formatting 2019-07-06 16:11:35 -07:00
FitsStubImagePlugin.py Format with Black 2019-06-10 18:22:46 +03:00
FliImagePlugin.py Format with Black 2019-06-10 18:22:46 +03:00
FontFile.py Introduce isort to automate import ordering and formatting 2019-07-06 16:11:35 -07:00
FpxImagePlugin.py Introduce isort to automate import ordering and formatting 2019-07-06 16:11:35 -07:00
FtexImagePlugin.py Introduce isort to automate import ordering and formatting 2019-07-06 16:11:35 -07:00
GbrImagePlugin.py Format with Black 2019-06-10 18:22:46 +03:00
GdImageFile.py Format with Black 2019-06-10 18:22:46 +03:00
GifImagePlugin.py Move several imports to the top-level of the file 2019-10-07 06:28:36 -07:00
GimpGradientFile.py Introduce isort to automate import ordering and formatting 2019-07-06 16:11:35 -07:00
GimpPaletteFile.py Introduce isort to automate import ordering and formatting 2019-07-06 16:11:35 -07:00
GribStubImagePlugin.py Format with Black 2019-06-10 18:22:46 +03:00
Hdf5StubImagePlugin.py Format with Black 2019-06-10 18:22:46 +03:00
IcnsImagePlugin.py Move several imports to the top-level of the file 2019-10-07 06:28:36 -07:00
IcoImagePlugin.py Added decompression bomb checks 2019-09-30 18:45:13 +10:00
Image.py Improve handling of file resources 2019-10-12 08:27:17 -07:00
ImageChops.py Changed docstring to be consistent 2019-01-01 20:44:04 +11:00
ImageCms.py Introduce isort to automate import ordering and formatting 2019-07-06 16:11:35 -07:00
ImageColor.py Introduce isort to automate import ordering and formatting 2019-07-06 16:11:35 -07:00
ImageDraw.py Merge pull request #3978 from radarhere/stroke 2019-09-06 19:14:49 +10:00
ImageDraw2.py Format with Black 2019-06-10 18:22:46 +03:00
ImageEnhance.py Format with Black 2019-06-10 18:22:46 +03:00
ImageFile.py Improve handling of file resources 2019-10-12 08:27:17 -07:00
ImageFilter.py Format with Black 2019-06-10 18:22:46 +03:00
ImageFont.py Move several imports to the top-level of the file 2019-10-07 06:28:36 -07:00
ImageGrab.py Move several imports to the top-level of the file 2019-10-07 06:28:36 -07:00
ImageMath.py Format with Black 2019-06-10 18:22:46 +03:00
ImageMode.py Added mode descriptors for all I;16 modes 2019-06-12 20:33:00 +10:00
ImageMorph.py Introduce isort to automate import ordering and formatting 2019-07-06 16:11:35 -07:00
ImageOps.py Do not calculate the crop width if it is already known 2019-09-29 14:26:32 +10:00
ImagePalette.py Introduce isort to automate import ordering and formatting 2019-07-06 16:11:35 -07:00
ImagePath.py Introduce isort to automate import ordering and formatting 2019-07-06 16:11:35 -07:00
ImageQt.py Drop support for EOL PyQt4 and PySide 2019-09-30 17:58:31 +03:00
ImageSequence.py Added ImageSequence all_frames 2019-06-23 07:34:39 +10:00
ImageShow.py Changed WindowsViewer format to PNG 2019-09-21 09:11:32 +10:00
ImageStat.py Introduce isort to automate import ordering and formatting 2019-07-06 16:11:35 -07:00
ImageTk.py Format with Black 2019-06-10 18:22:46 +03:00
ImageTransform.py Format with Black 2019-06-10 18:22:46 +03:00
ImageWin.py Format with Black 2019-06-10 18:22:46 +03:00
ImImagePlugin.py Introduce isort to automate import ordering and formatting 2019-07-06 16:11:35 -07:00
ImtImagePlugin.py Format with Black 2019-06-10 18:22:46 +03:00
IptcImagePlugin.py Introduce isort to automate import ordering and formatting 2019-07-06 16:11:35 -07:00
Jpeg2KImagePlugin.py Introduce isort to automate import ordering and formatting 2019-07-06 16:11:35 -07:00
JpegImagePlugin.py Move several imports to the top-level of the file 2019-10-07 06:28:36 -07:00
JpegPresets.py Format with Black 2019-06-10 18:22:46 +03:00
McIdasImagePlugin.py Introduce isort to automate import ordering and formatting 2019-07-06 16:11:35 -07:00
MicImagePlugin.py Introduce isort to automate import ordering and formatting 2019-07-06 16:11:35 -07:00
MpegImagePlugin.py Format with Black 2019-06-10 18:22:46 +03:00
MpoImagePlugin.py Changed the Image getexif method to return a shared Exif instance 2019-08-23 06:13:20 +10:00
MspImagePlugin.py Introduce isort to automate import ordering and formatting 2019-07-06 16:11:35 -07:00
PaletteFile.py Introduce isort to automate import ordering and formatting 2019-07-06 16:11:35 -07:00
PalmImagePlugin.py Format with Black 2019-06-11 11:42:05 +03:00
PcdImagePlugin.py Format with Black 2019-06-10 18:22:46 +03:00
PcfFontFile.py Introduce isort to automate import ordering and formatting 2019-07-06 16:11:35 -07:00
PcxImagePlugin.py Introduce isort to automate import ordering and formatting 2019-07-06 16:11:35 -07:00
PdfImagePlugin.py Introduce isort to automate import ordering and formatting 2019-07-06 16:11:35 -07:00
PdfParser.py Introduce isort to automate import ordering and formatting 2019-07-06 16:11:35 -07:00
PixarImagePlugin.py Format with Black 2019-06-10 18:22:46 +03:00
PngImagePlugin.py Merge pull request #3965 from radarhere/truncated 2019-09-20 22:53:52 +03:00
PpmImagePlugin.py Format with Black 2019-06-10 18:22:46 +03:00
PsdImagePlugin.py Corrected negative seeks 2019-09-30 18:31:18 +10:00
PSDraw.py Introduce isort to automate import ordering and formatting 2019-07-06 16:11:35 -07:00
PyAccess.py Introduce isort to automate import ordering and formatting 2019-07-06 16:11:35 -07:00
SgiImagePlugin.py Introduce isort to automate import ordering and formatting 2019-07-06 16:11:35 -07:00
SpiderImagePlugin.py Improve handling of file resources 2019-10-12 08:27:17 -07:00
SunImagePlugin.py Format with Black 2019-06-10 18:22:46 +03:00
TarIO.py Improve handling of file resources 2019-10-12 08:27:17 -07:00
TgaImagePlugin.py Introduce isort to automate import ordering and formatting 2019-07-06 16:11:35 -07:00
TiffImagePlugin.py Merge pull request #4114 from radarhere/tiff_size 2019-10-05 02:33:08 +10:00
TiffTags.py Corrected tag types 2019-09-06 19:33:57 +10:00
WalImageFile.py Format with Black 2019-06-10 18:22:46 +03:00
WebPImagePlugin.py Introduce isort to automate import ordering and formatting 2019-07-06 16:11:35 -07:00
WmfImagePlugin.py Introduce isort to automate import ordering and formatting 2019-07-06 16:11:35 -07:00
XbmImagePlugin.py Introduce isort to automate import ordering and formatting 2019-07-06 16:11:35 -07:00
XpmImagePlugin.py Introduce isort to automate import ordering and formatting 2019-07-06 16:11:35 -07:00
XVThumbImagePlugin.py Format with Black 2019-06-10 18:22:46 +03:00