From 165d84abbf43a827db9cf3b229b1b9864846abb7 Mon Sep 17 00:00:00 2001 From: Corry Haines Date: Thu, 29 Dec 2022 09:35:14 -0800 Subject: [PATCH] Fixes developed from mypy_django script (#312) --- activities/models/emoji.py | 2 +- core/files.py | 10 +++++++--- core/signatures.py | 2 +- mediaproxy/views.py | 2 +- stator/models.py | 6 ++++-- 5 files changed, 14 insertions(+), 8 deletions(-) diff --git a/activities/models/emoji.py b/activities/models/emoji.py index f657337..89f4dbd 100644 --- a/activities/models/emoji.py +++ b/activities/models/emoji.py @@ -188,7 +188,7 @@ class Emoji(StatorModel): return self.fullcode @classmethod - def emojis_from_content(cls, content: str, domain: Domain | None) -> list[str]: + def emojis_from_content(cls, content: str, domain: Domain | None) -> list["Emoji"]: """ Return a parsed and sanitized of emoji found in content without the surrounding ':'. diff --git a/core/files.py b/core/files.py index dc82aa4..21a862b 100644 --- a/core/files.py +++ b/core/files.py @@ -8,13 +8,17 @@ from django.core.files.base import ContentFile from PIL import Image, ImageOps +class ImageFile(File): + image: Image + + def resize_image( image: File, *, size: tuple[int, int], cover=True, keep_format=False, -) -> File: +) -> ImageFile: """ Resizes an image to fit insize the given size (cropping one dimension to fit if needed) @@ -28,10 +32,10 @@ def resize_image( new_image_bytes = io.BytesIO() if keep_format: resized_image.save(new_image_bytes, format=img.format) - file = File(new_image_bytes) + file = ImageFile(new_image_bytes) else: resized_image.save(new_image_bytes, format="webp") - file = File(new_image_bytes, name="image.webp") + file = ImageFile(new_image_bytes, name="image.webp") file.image = resized_image return file diff --git a/core/signatures.py b/core/signatures.py index 8fcf31e..2632960 100644 --- a/core/signatures.py +++ b/core/signatures.py @@ -245,7 +245,7 @@ class HttpSignature: and response.status_code != 404 ): raise ValueError( - f"POST error to {uri}: {response.status_code} {response.content}" + f"POST error to {uri}: {response.status_code} {response.content!r}" ) return response diff --git a/mediaproxy/views.py b/mediaproxy/views.py index f2b4cb0..8bbbb45 100644 --- a/mediaproxy/views.py +++ b/mediaproxy/views.py @@ -58,7 +58,7 @@ class BaseProxyView(View): }, ) - def get_remote_url(self): + def get_remote_url(self) -> str: raise NotImplementedError() diff --git a/stator/models.py b/stator/models.py index c69ed0f..8991a49 100644 --- a/stator/models.py +++ b/stator/models.py @@ -46,6 +46,8 @@ class StatorModel(models.Model): concrete model yourself. """ + state: StateField + # If this row is up for transition attempts (which it always is on creation!) state_ready = models.BooleanField(default=True) @@ -75,11 +77,11 @@ class StatorModel(models.Model): return cls._meta.get_field("state").graph @property - def state_age(self) -> int: + def state_age(self) -> float: return (timezone.now() - self.state_changed).total_seconds() @classmethod - async def atransition_schedule_due(cls, now=None) -> models.QuerySet: + async def atransition_schedule_due(cls, now=None): """ Finds instances of this model that need to run and schedule them. """