Do not retry specified formats if they failed when opening #6893
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When opening an image, Pillow loop through the different possible formats.
Pillow/src/PIL/Image.py
Lines 3242 to 3244 in 43bb035
If I add a
print
statement to see which formats it checks,and then attempt to open a SPIDER image, while only asking Pillow to check the JPEG format,
it prints
JPEG is checked twice.
This is because in the following code, Pillow doesn't recognise that
formats
is a fixed list, and that callinginit()
will not increase the number of formats to try.Pillow/src/PIL/Image.py
Lines 3268 to 3272 in 43bb035
So this PR changes it to only retry
_open_core
ifformats
has not been specified.But wait, you say, you've also skipped calling
init()
. What if the needed format hasn't been imported before the call to_open_core
?Not to worry.
_open_core
already automatically callsinit()
if there is something surprising informats
Pillow/src/PIL/Image.py
Lines 3242 to 3246 in 43bb035