Fixes developed from mypy_django script (#312)

This commit is contained in:
Corry Haines 2022-12-29 09:35:14 -08:00 committed by GitHub
parent cc7824394b
commit 165d84abbf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 14 additions and 8 deletions

View file

@ -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 ':'.

View file

@ -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

View file

@ -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

View file

@ -58,7 +58,7 @@ class BaseProxyView(View):
},
)
def get_remote_url(self):
def get_remote_url(self) -> str:
raise NotImplementedError()

View file

@ -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.
"""