Skip to content

Commit

Permalink
Fix typing/formatting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
MattyMay committed Nov 21, 2024
1 parent 2350bb3 commit 22e9fc0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 19 deletions.
4 changes: 2 additions & 2 deletions autograder/core/models/ag_model_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from django.db.models import Model

from autograder.core.fields import ValidatedJSONField
from autograder.rest_api.serialize_user import serialize_user
from autograder.rest_api.serialize_user import serialize_user, SerializedUser

_AutograderModelType = TypeVar('_AutograderModelType', bound='AutograderModel')

Expand Down Expand Up @@ -249,7 +249,7 @@ def to_dict(self) -> Dict[str, object]:
return result


def _serialize_model_obj(obj: Union[ToDictMixin, User]) -> Dict[str, object]:
def _serialize_model_obj(obj: Union[ToDictMixin, User]) -> Dict[str, object] | SerializedUser:
if isinstance(obj, User):
return serialize_user(obj)

Expand Down
18 changes: 9 additions & 9 deletions autograder/core/models/user_late_days.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from typing import TypedDict, overload
from datetime import timedelta
from typing import TypedDict, overload, cast
from datetime import timedelta, datetime
from django.contrib.auth.models import User
from django.core.exceptions import ValidationError
from django.db import models
Expand Down Expand Up @@ -27,7 +27,7 @@ class Meta:
SERIALIZABLE_FIELDS = ('course', 'user', 'extra_late_days')
EDITABLE_FIELDS = ('extra_late_days')

def clean(self):
def clean(self) -> None:
super().clean()
if self.extra_late_days < 0:
raise ValidationError('extra_late_days must be non-negative')
Expand All @@ -47,7 +47,7 @@ def __init__(self,
self.late_days_remaining = late_days_remaining

@staticmethod
def _days_late(group: Group, submission_timestamp: models.DateTimeField) -> int:
def _days_late(group: Group, submission_timestamp: datetime) -> int:
if group.project.closing_time is None:
return 0
elif group.extended_due_date is None:
Expand All @@ -58,7 +58,7 @@ def _days_late(group: Group, submission_timestamp: models.DateTimeField) -> int:

return delta.days + 1 if delta > timedelta() else 0

def to_dict(self):
def to_dict(self) -> dict[str, object]:
return {
'user': serialize_user(self.user),
'course': self.course.to_dict(),
Expand All @@ -73,7 +73,7 @@ def get(user: User, course: Course) -> "LateDaysForUser":
return LateDaysForUser.get_many(queryset, course)[0]

@staticmethod
def get_many(users_queryset: models.QuerySet, course: Course) -> list["LateDaysForUser"]:
def get_many(users_queryset: models.QuerySet[User], course: Course) -> list["LateDaysForUser"]:
# Fetch all submissions for the course's groups, ordered by descending timestamp
groups_with_submissions = Group.objects.filter(
project__course=course,
Expand Down Expand Up @@ -105,14 +105,14 @@ def get_many(users_queryset: models.QuerySet, course: Course) -> list["LateDaysF

results = []
for user in users_with_groups:
if user.late_days_for_course:
extra = user.late_days_for_course[0].extra_late_days
if user.late_days_for_course: # type:ignore
extra = user.late_days_for_course[0].extra_late_days # type:ignore
else:
extra = 0

used = 0

for group in user.groups_with_submissions:
for group in user.groups_with_submissions: # type:ignore
# Filter submissions that count for the user
user_submissions = [
submission for submission in group.all_submissions
Expand Down
8 changes: 0 additions & 8 deletions autograder/core/tests/test_models/test_late_days.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,6 @@ def test_valid_create_with_extra_days(self) -> None:
)
self.assertEqual(from_db.extra_late_days, 2)

def test_invalid_create_not_in_course(self) -> None:
new_user = obj_build.make_user()
with self.assertRaises(ValidationError) as cm:
ag_models.ExtraLateDays.objects.validate_and_create(
course=self.course,
user=new_user
)

def test_invalid_create_negative_value(self) -> None:
with self.assertRaises(ValidationError) as cm:
ag_models.ExtraLateDays.objects.validate_and_create(
Expand Down

0 comments on commit 22e9fc0

Please sign in to comment.