Skip to content

Commit 82b266a

Browse files
committed
Assert fp is not None
1 parent 7e15c54 commit 82b266a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+77
-4
lines changed

Tests/test_file_bufrstub.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ def open(self, im: ImageFile.StubImageFile) -> None:
6161

6262
def load(self, im: ImageFile.StubImageFile) -> Image.Image:
6363
self.loaded = True
64+
assert im.fp is not None
6465
im.fp.close()
6566
return Image.new("RGB", (1, 1))
6667

Tests/test_file_cur.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ def test_invalid_file() -> None:
2626
no_cursors_file = "Tests/images/no_cursors.cur"
2727

2828
cur = CurImagePlugin.CurImageFile(TEST_FILE)
29+
assert cur.fp is not None
2930
cur.fp.close()
3031
with open(no_cursors_file, "rb") as cur.fp:
3132
with pytest.raises(TypeError):

Tests/test_file_gribstub.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ def open(self, im: Image.Image) -> None:
6161

6262
def load(self, im: Image.Image) -> Image.Image:
6363
self.loaded = True
64+
assert im.fp is not None
6465
im.fp.close()
6566
return Image.new("RGB", (1, 1))
6667

Tests/test_file_hdf5stub.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ def open(self, im: Image.Image) -> None:
6363

6464
def load(self, im: Image.Image) -> Image.Image:
6565
self.loaded = True
66+
assert im.fp is not None
6667
im.fp.close()
6768
return Image.new("RGB", (1, 1))
6869

Tests/test_file_jpeg.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1110,8 +1110,9 @@ def test_fd_leak(self, tmp_path: Path) -> None:
11101110
im.save(tmpfile)
11111111

11121112
im = Image.open(tmpfile)
1113+
assert im.fp is not None
1114+
assert not im.fp.closed
11131115
fp = im.fp
1114-
assert not fp.closed
11151116
with pytest.raises(OSError):
11161117
os.remove(tmpfile)
11171118
im.load()

Tests/test_file_libtiff.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,15 @@
1111

1212
import pytest
1313

14-
from PIL import Image, ImageFilter, ImageOps, TiffImagePlugin, TiffTags, features
14+
from PIL import (
15+
Image,
16+
ImageFile,
17+
ImageFilter,
18+
ImageOps,
19+
TiffImagePlugin,
20+
TiffTags,
21+
features,
22+
)
1523
from PIL.TiffImagePlugin import OSUBFILETYPE, SAMPLEFORMAT, STRIPOFFSETS, SUBIFD
1624

1725
from .helper import (
@@ -564,8 +572,9 @@ def test_bw_compression_w_rgb(self, compression: str, tmp_path: Path) -> None:
564572
im.save(out, compression=compression)
565573

566574
def test_fp_leak(self) -> None:
567-
im: Image.Image | None = Image.open("Tests/images/hopper_g4_500.tif")
575+
im: ImageFile.ImageFile | None = Image.open("Tests/images/hopper_g4_500.tif")
568576
assert im is not None
577+
assert im.fp is not None
569578
fn = im.fp.fileno()
570579

571580
os.fstat(fn)

Tests/test_file_tiff.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -956,6 +956,7 @@ def test_close_on_load_exclusive(self, tmp_path: Path) -> None:
956956

957957
im = Image.open(tmpfile)
958958
fp = im.fp
959+
assert fp is not None
959960
assert not fp.closed
960961
im.load()
961962
assert fp.closed
@@ -969,6 +970,7 @@ def test_close_on_load_nonexclusive(self, tmp_path: Path) -> None:
969970
with open(tmpfile, "rb") as f:
970971
im = Image.open(f)
971972
fp = im.fp
973+
assert fp is not None
972974
assert not fp.closed
973975
im.load()
974976
assert not fp.closed
@@ -1019,8 +1021,9 @@ def test_fd_leak(self, tmp_path: Path) -> None:
10191021
im.save(tmpfile)
10201022

10211023
im = Image.open(tmpfile)
1024+
assert im.fp is not None
1025+
assert not im.fp.closed
10221026
fp = im.fp
1023-
assert not fp.closed
10241027
with pytest.raises(OSError):
10251028
os.remove(tmpfile)
10261029
im.load()

Tests/test_image_load.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ def test_close_after_load(caplog: pytest.LogCaptureFixture) -> None:
3838
def test_contextmanager() -> None:
3939
fn = None
4040
with Image.open("Tests/images/hopper.gif") as im:
41+
assert im.fp is not None
4142
fn = im.fp.fileno()
4243
os.fstat(fn)
4344

docs/example/DdsImagePlugin.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ class DdsImageFile(ImageFile.ImageFile):
213213
format_description = "DirectDraw Surface"
214214

215215
def _open(self) -> None:
216+
assert self.fp is not None
216217
if not _accept(self.fp.read(4)):
217218
msg = "not a DDS file"
218219
raise SyntaxError(msg)

src/PIL/BlpImagePlugin.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ class BlpImageFile(ImageFile.ImageFile):
258258
format_description = "Blizzard Mipmap Format"
259259

260260
def _open(self) -> None:
261+
assert self.fp is not None
261262
self.magic = self.fp.read(4)
262263
if not _accept(self.magic):
263264
msg = f"Bad BLP magic {repr(self.magic)}"

0 commit comments

Comments
 (0)