Skip to content

Commit dd753f4

Browse files
authored
Merge pull request #7725 from radarhere/type_hints_tga
2 parents 6fd85cf + 54c96df commit dd753f4

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

src/PIL/TgaImagePlugin.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from __future__ import annotations
1919

2020
import warnings
21+
from io import BytesIO
2122

2223
from . import Image, ImageFile, ImagePalette
2324
from ._binary import i16le as i16
@@ -49,8 +50,10 @@ class TgaImageFile(ImageFile.ImageFile):
4950
format = "TGA"
5051
format_description = "Targa"
5152

52-
def _open(self):
53+
def _open(self) -> None:
5354
# process header
55+
assert self.fp is not None
56+
5457
s = self.fp.read(18)
5558

5659
id_len = s[0]
@@ -151,8 +154,9 @@ def _open(self):
151154
except KeyError:
152155
pass # cannot decode
153156

154-
def load_end(self):
157+
def load_end(self) -> None:
155158
if self._flip_horizontally:
159+
assert self.im is not None
156160
self.im = self.im.transpose(Image.Transpose.FLIP_LEFT_RIGHT)
157161

158162

@@ -171,7 +175,7 @@ def load_end(self):
171175
}
172176

173177

174-
def _save(im, fp, filename):
178+
def _save(im: Image.Image, fp: BytesIO, filename: str) -> None:
175179
try:
176180
rawmode, bits, colormaptype, imagetype = SAVE[im.mode]
177181
except KeyError as e:
@@ -194,6 +198,7 @@ def _save(im, fp, filename):
194198
warnings.warn("id_section has been trimmed to 255 characters")
195199

196200
if colormaptype:
201+
assert im.im is not None
197202
palette = im.im.getpalette("RGB", "BGR")
198203
colormaplength, colormapentry = len(palette) // 3, 24
199204
else:

0 commit comments

Comments
 (0)