We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 0a668bb commit c13ebc1Copy full SHA for c13ebc1
pictures/models.py
@@ -6,6 +6,7 @@
6
import math
7
from fractions import Fraction
8
from pathlib import Path
9
+from types import NotImplementedType
10
11
from django.core import checks
12
from django.core.files.base import ContentFile
@@ -105,7 +106,7 @@ def name(self) -> str:
105
106
def path(self) -> Path:
107
return Path(self.storage.path(self.name))
108
- def process(self, image) -> Image:
109
+ def process(self, image) -> Image.Image:
110
image = ImageOps.exif_transpose(image) # crates a copy
111
height = self.height or self.width / Fraction(*image.size)
112
size = math.floor(self.width), math.floor(height)
@@ -130,7 +131,7 @@ def delete(self):
130
131
132
133
class PictureFieldFile(ImageFieldFile):
- def __xor__(self, other) -> tuple[set[Picture], set[Picture]]:
134
+ def __xor__(self, other) -> tuple[set[Picture], set[Picture]] | NotImplementedType:
135
"""Return the new and obsolete :class:`Picture` instances."""
136
if not isinstance(other, PictureFieldFile):
137
return NotImplemented
@@ -192,7 +193,7 @@ def height(self):
192
193
return self._get_image_dimensions()[1]
194
195
@property
- def aspect_ratios(self) -> {Fraction | None: {str: {int: Picture}}}:
196
+ def aspect_ratios(self) -> dict[Fraction | None, dict[str, dict[int, Picture]]]:
197
self._require_file()
198
return self.get_picture_files(
199
file_name=self.name,
@@ -210,7 +211,7 @@ def get_picture_files(
210
211
img_height: int,
212
storage: Storage,
213
field: PictureField,
- ) -> {Fraction | None: {str: {int: Picture}}}:
214
+ ) -> dict[Fraction | None, dict[str, dict[int, Picture]]]:
215
PictureClass = import_string(conf.get_settings().PICTURE_CLASS)
216
return {
217
ratio: {
pictures/utils.py
@@ -61,7 +61,7 @@ def sizes(
61
62
63
def source_set(
64
- size: (int, int), *, ratio: str | Fraction | None, max_width: int, cols: int
+ size: tuple[int, int], *, ratio: str | Fraction | None, max_width: int, cols: int
65
) -> set:
66
ratio = Fraction(ratio) if ratio else None
67
img_width, img_height = size
@@ -82,8 +82,8 @@ def placeholder(width: int, height: int, alt):
82
hue = random.randint(0, 360) # NoQA S311
83
img = Image.new("RGB", (width, height), color=f"hsl({hue}, 40%, 80%)")
84
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%)")
+ draw.line((0, 0, width, height), width=3, fill=f"hsl({hue}, 60%, 20%)")
+ draw.line((0, height, width, 0), width=3, fill=f"hsl({hue}, 60%, 20%)")
87
draw.rectangle(
88
(width / 4, height / 4, width * 3 / 4, height * 3 / 4),
89
fill=f"hsl({hue}, 40%, 80%)",
tests/test_utils.py
@@ -145,14 +145,14 @@ def test_placeholder():
145
assert img.height == 1200
146
147
148
-class TestPicture(Picture):
+class SamplePicture(Picture):
149
150
def url(self):
151
return f"/media/{self.parent_name}"
152
153
154
def test_reconstruct(image_upload_file):
155
- picture = TestPicture(
+ picture = SamplePicture(
156
image_upload_file.name,
157
"WEBP",
158
"16/9",
@@ -173,7 +173,7 @@ def test_reconstruct(image_upload_file):
173
"storage": default_storage,
174
"width": 100,
175
},
176
- ) == TestPicture(
+ ) == SamplePicture(
177
"test.jpg",
178
"JPEG",
179
0 commit comments