fix(export): move EXIF tag parsing out of the finally block - #907
Merged
marcinz606 merged 1 commit intoAug 19, 2026
Merged
Conversation
`_read_source_meta_exif` silences the tifffile logger, opens the embedded TIFF block in a `try`, and then does all of its parsing inside the `finally`, ending with a `return`. Two consequences. A `return` in `finally` discards any in-flight exception, so Python 3.14 emits `SyntaxWarning: 'return' in a 'finally' block` on every import of this module. And the parsing reads `tif`, which is unbound when `TiffFile()` raises, so a malformed EXIF block surfaced as `UnboundLocalError` instead of the real tifffile error. The outer `except Exception` swallowed either way, so callers still got an empty `_SourceMeta`, but the real cause was unreachable. The `finally` now does only what it exists for, restoring the logger level. The parsing and the `return` sit after it, so a decode failure propagates normally. Behaviour is unchanged: a good EXIF block parses as before, a bad one still returns an empty `_SourceMeta`. Adds `TestSourceMetaExifFallback`, which had no coverage. The SyntaxWarning-free assertion fails against the current source and passes after.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
_read_source_meta_exifsilences the tifffile logger, opens the embedded TIFF block in atry, then does all of its parsing inside thefinallyand returns from there.Two consequences. A
returninfinallydiscards any in-flight exception, so Python 3.14 emitsSyntaxWarning: 'return' in a 'finally' blockon every import of this module. And the parsing readstif, which is unbound whenTiffFile()raises, so a malformed EXIF block came back asUnboundLocalErrorrather than the real tifffile error:The outer
except Exceptioncaught either way, so callers still got an empty_SourceMetaand no behaviour changes here. The real cause was just unreachable.The
finallynow only restores the logger level, and the parsing sits after it.TestSourceMetaExifFallbackis new; this function had no coverage. The SyntaxWarning assertion fails against the current source and passes after; the other three pass both ways.Windows 11, Python 3.14.7, your
[dev]group:4306 passed, 10 skippedontests/with-m "not slow and not metrics". The 2 failures aretest_backend_registry.pyplustek cases needing the optional extra, failing identically without this change.ruff checkandruff format --checkclean.Your CI is
ubuntu-lateston one Python, so the warning would not surface there yet.