FIX: Gracefully handle empty files for imgmath depth extraction - #14468
Open
timhoffm wants to merge 3 commits into
Open
FIX: Gracefully handle empty files for imgmath depth extraction#14468timhoffm wants to merge 3 commits into
timhoffm wants to merge 3 commits into
Conversation
Closes sphinx-doc#14466. While empty files are likely an error `read_svg_depth()` is not the place to flag empty files. It is designed to handle files without depth comment, and that should also be true for the edge case of an empty file.
jdillard
approved these changes
Jul 30, 2026
jdillard
left a comment
Member
There was a problem hiding this comment.
LGTM. The only concern I see (and it is a small one), is that the whole SVG is loaded into memory with list(f). To keep the small line buffer you could do something like:
with open(filename, encoding='utf-8') as f:
line = None
for line in f:
pass
if line is not None:
if matched := depthsvgcomment_re.match(line):
return int(matched.group(1))
return None
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.
Closes #14466.
While empty files are unexpected and likely an error,
read_svg_depth()is not the place to flag empty files. It is designed to handle files without depth comment, and that should also be true for the edge case of an empty file.