Close image on ImageFont exception by radarhere · Pull Request #9304 · python-pillow/Pillow
Fixes an unclosed file warning from https://github.com/python-pillow/Pillow/actions/runs/19457141721/job/55673162157#step:11:5270
Tests/test_imagefont.py::test_load_invalid_file
/Users/runner/work/Pillow/Pillow/Tests/test_imagefont.py:497: ResourceWarning: unclosed file <_io.BufferedReader name='Tests/images/1_trns.png'>
with pytest.raises(SyntaxError, match="Not a PILfont file"):
by adding image.close() when exceptions are raised in ImageFont._load_pilfont_data(). This method is only called internally after creating the ImageFont instance, so there's no need for the image afterwards.