Skip to content

Commit c13ebc1

Browse files
committed
Fix various type hints
1 parent 0a668bb commit c13ebc1

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed

pictures/models.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import math
77
from fractions import Fraction
88
from pathlib import Path
9+
from types import NotImplementedType
910

1011
from django.core import checks
1112
from django.core.files.base import ContentFile
@@ -105,7 +106,7 @@ def name(self) -> str:
105106
def path(self) -> Path:
106107
return Path(self.storage.path(self.name))
107108

108-
def process(self, image) -> Image:
109+
def process(self, image) -> Image.Image:
109110
image = ImageOps.exif_transpose(image) # crates a copy
110111
height = self.height or self.width / Fraction(*image.size)
111112
size = math.floor(self.width), math.floor(height)
@@ -130,7 +131,7 @@ def delete(self):
130131

131132

132133
class PictureFieldFile(ImageFieldFile):
133-
def __xor__(self, other) -> tuple[set[Picture], set[Picture]]:
134+
def __xor__(self, other) -> tuple[set[Picture], set[Picture]] | NotImplementedType:
134135
"""Return the new and obsolete :class:`Picture` instances."""
135136
if not isinstance(other, PictureFieldFile):
136137
return NotImplemented
@@ -192,7 +193,7 @@ def height(self):
192193
return self._get_image_dimensions()[1]
193194

194195
@property
195-
def aspect_ratios(self) -> {Fraction | None: {str: {int: Picture}}}:
196+
def aspect_ratios(self) -> dict[Fraction | None, dict[str, dict[int, Picture]]]:
196197
self._require_file()
197198
return self.get_picture_files(
198199
file_name=self.name,
@@ -210,7 +211,7 @@ def get_picture_files(
210211
img_height: int,
211212
storage: Storage,
212213
field: PictureField,
213-
) -> {Fraction | None: {str: {int: Picture}}}:
214+
) -> dict[Fraction | None, dict[str, dict[int, Picture]]]:
214215
PictureClass = import_string(conf.get_settings().PICTURE_CLASS)
215216
return {
216217
ratio: {

pictures/utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def sizes(
6161

6262

6363
def source_set(
64-
size: (int, int), *, ratio: str | Fraction | None, max_width: int, cols: int
64+
size: tuple[int, int], *, ratio: str | Fraction | None, max_width: int, cols: int
6565
) -> set:
6666
ratio = Fraction(ratio) if ratio else None
6767
img_width, img_height = size
@@ -82,8 +82,8 @@ def placeholder(width: int, height: int, alt):
8282
hue = random.randint(0, 360) # NoQA S311
8383
img = Image.new("RGB", (width, height), color=f"hsl({hue}, 40%, 80%)")
8484
draw = ImageDraw.Draw(img)
85-
draw.line(((0, 0, width, height)), width=3, fill=f"hsl({hue}, 60%, 20%)")
86-
draw.line(((0, height, width, 0)), width=3, fill=f"hsl({hue}, 60%, 20%)")
85+
draw.line((0, 0, width, height), width=3, fill=f"hsl({hue}, 60%, 20%)")
86+
draw.line((0, height, width, 0), width=3, fill=f"hsl({hue}, 60%, 20%)")
8787
draw.rectangle(
8888
(width / 4, height / 4, width * 3 / 4, height * 3 / 4),
8989
fill=f"hsl({hue}, 40%, 80%)",

tests/test_utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,14 +145,14 @@ def test_placeholder():
145145
assert img.height == 1200
146146

147147

148-
class TestPicture(Picture):
148+
class SamplePicture(Picture):
149149
@property
150150
def url(self):
151151
return f"/media/{self.parent_name}"
152152

153153

154154
def test_reconstruct(image_upload_file):
155-
picture = TestPicture(
155+
picture = SamplePicture(
156156
image_upload_file.name,
157157
"WEBP",
158158
"16/9",
@@ -173,7 +173,7 @@ def test_reconstruct(image_upload_file):
173173
"storage": default_storage,
174174
"width": 100,
175175
},
176-
) == TestPicture(
176+
) == SamplePicture(
177177
"test.jpg",
178178
"JPEG",
179179
"16/9",

0 commit comments

Comments
 (0)