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 0ec2e4d commit a5aa47aCopy full SHA for a5aa47a
pictures/models.py
@@ -105,7 +105,7 @@ def name(self) -> str:
105
def path(self) -> Path:
106
return Path(self.storage.path(self.name))
107
108
- def process(self, image) -> Image:
+ def process(self, image) -> Image.Image:
109
image = ImageOps.exif_transpose(image) # crates a copy
110
height = self.height or self.width / Fraction(*image.size)
111
size = math.floor(self.width), math.floor(height)
@@ -130,7 +130,9 @@ def delete(self):
130
131
132
class PictureFieldFile(ImageFieldFile):
133
- def __xor__(self, other) -> tuple[set[Picture], set[Picture]]:
+ def __xor__(
134
+ self, other
135
+ ) -> tuple[set[Picture], set[Picture]] | type[NotImplemented]:
136
"""Return the new and obsolete :class:`Picture` instances."""
137
if not isinstance(other, PictureFieldFile):
138
return NotImplemented
@@ -192,7 +194,7 @@ def height(self):
192
194
return self._get_image_dimensions()[1]
193
195
196
@property
- def aspect_ratios(self) -> {Fraction | None: {str: {int: Picture}}}:
197
+ def aspect_ratios(self) -> dict[Fraction | None, dict[str, dict[int, Picture]]]:
198
self._require_file()
199
return self.get_picture_files(
200
file_name=self.name,
@@ -210,7 +212,7 @@ def get_picture_files(
210
212
img_height: int,
211
213
storage: Storage,
214
field: PictureField,
- ) -> {Fraction | None: {str: {int: Picture}}}:
215
+ ) -> dict[Fraction | None, dict[str, dict[int, Picture]]]:
216
PictureClass = import_string(conf.get_settings().PICTURE_CLASS)
217
return {
218
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