Commit Graph

18 Commits

Author SHA1 Message Date
Hugo
cc63f66575 Merge remote-tracking branch 'upstream/master' into rm-2.7 2019-11-01 13:22:56 +02:00
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
Hugo
538d9e2e5d Upgrade Python syntax with pyupgrade --py3-plus 2019-10-07 14:30:59 +03:00
nulano
17d9938ece spider labrec ceil 2019-09-27 22:10:49 +02:00
Jon Dufresne
d50445ff30 Introduce isort to automate import ordering and formatting
Similar to the recent adoption of Black. isort is a Python utility to
sort imports alphabetically and automatically separate into sections. By
using isort, contributors can quickly and automatically conform to the
projects style without thinking. Just let the tool do it.

Uses the configuration recommended by the Black to avoid conflicts of
style.

Rewrite TestImageQt.test_deprecated to no rely on import order.
2019-07-06 16:11:35 -07:00
Hugo
53a7e35004 Format with Black 2019-06-10 18:22:46 +03:00
Andrew Murray
9cc7e8ce95 Improved docstring 2019-03-24 22:07:19 +11:00
Andrew Murray
71b64dcf73 Only close __fp if not fp 2019-01-04 12:29:23 +11:00
Hugo
3ed5dcc928
Merge pull request #3467 from hugovk/lint-can-fail
CI: Allow lint job to fail
2018-12-13 21:09:58 +02:00
Hugo
c353225851 Prefer 'except Exception:' to bare 'except:' 2018-12-04 23:25:28 +02:00
Andrew Murray
47775f3d50 Resolve __fp when closing and deleting 2018-11-17 21:56:06 +11:00
Andrew Murray
0adeb82e98 Changed Image size property to be read-only by default 2018-09-30 13:45:18 +10:00
Jon Dufresne
37f10651bd Clean up commented out debug print statements 2018-09-04 20:02:42 -07:00
Andrew Murray
30c9ca15fb Fixed docstrings 2018-04-18 16:00:17 +10:00
Andrew Murray
2202196162 Flake8 blank line fixes 2018-03-04 21:36:33 +11:00
Andrew Murray
696b3819e8 Combined two excerpt statements 2018-01-06 21:58:05 +11:00
Andrew Murray
3c73043509 Simplified use of sys.argv 2018-01-06 21:57:29 +11:00
wiredfool
0bb3f4fee9 source layout reorg 2017-12-28 14:49:47 +00:00