Skip to content

Commit a440f4b

Browse files
author
Daniel Goshev
committed
Resolve mypy errors.
1 parent 66430ab commit a440f4b

File tree

4 files changed

+53
-23
lines changed

4 files changed

+53
-23
lines changed

.github/workflows/django.yml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,8 @@ jobs:
4646
key: python-${{ hashFiles('requirements/local.txt') }}-${{ hashFiles('requirements/base.txt') }}
4747
- name: Install dependencies
4848
run: pip install -r requirements/local.txt
49-
- name: Run isort
50-
uses: isort/isort-action@master
51-
- name: Run black
52-
uses: psf/black@stable
53-
- name: Run flake8
54-
run: flake8
49+
- name: Run ruff
50+
uses: chartboost/ruff-action@v1
5551
- name: Type check
5652
run: mypy --config mypy.ini styleguide_example/
5753
- name: Run tests

styleguide_example/common/models.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from django.db import models
2-
from django.db.models.query import F, Q
2+
from django.db.models import F, Q
33
from django.utils import timezone
44

55

@@ -29,7 +29,13 @@ class RandomModel(BaseModel):
2929
start_date = models.DateField()
3030
end_date = models.DateField()
3131

32-
simple_objects = models.ManyToManyField(SimpleModel, blank=True, related_name="random_objects")
32+
simple_objects = models.ManyToManyField(
33+
SimpleModel, blank=True, related_name="random_objects"
34+
)
3335

3436
class Meta:
35-
constraints = [models.CheckConstraint(name="start_date_before_end_date", check=Q(start_date__lt=F("end_date")))]
37+
constraints = [
38+
models.CheckConstraint(
39+
name="start_date_before_end_date", check=Q(start_date__lt=F("end_date"))
40+
)
41+
]

styleguide_example/testing_examples/models.py

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from uuid import uuid4
22

33
from django.db import models
4-
from django.db.models.query import F, Q
4+
from django.db.models import F, Q
55

66

77
class School(models.Model):
@@ -15,7 +15,9 @@ def __str__(self):
1515
class Student(models.Model):
1616
email = models.EmailField(max_length=255)
1717
identifier = models.UUIDField(default=uuid4)
18-
school = models.ForeignKey(School, related_name="students", on_delete=models.CASCADE)
18+
school = models.ForeignKey(
19+
School, related_name="students", on_delete=models.CASCADE
20+
)
1921

2022
class Meta:
2123
unique_together = (
@@ -30,14 +32,19 @@ def __str__(self):
3032
class SchoolCourse(models.Model):
3133
name = models.CharField(max_length=255)
3234
slug = models.SlugField(max_length=255)
33-
school = models.ForeignKey(School, related_name="school_courses", on_delete=models.CASCADE)
35+
school = models.ForeignKey(
36+
School, related_name="school_courses", on_delete=models.CASCADE
37+
)
3438

3539
start_date = models.DateField()
3640
end_date = models.DateField()
3741

3842
class Meta:
3943
constraints = [
40-
models.CheckConstraint(name="school_course_start_before_end", check=Q(start_date__lt=F("end_date")))
44+
models.CheckConstraint(
45+
name="school_course_start_before_end",
46+
check=Q(start_date__lt=F("end_date")),
47+
)
4148
]
4249

4350
unique_together = (
@@ -54,8 +61,12 @@ def __str__(self):
5461

5562

5663
class Roster(models.Model):
57-
student = models.ForeignKey(Student, related_name="rosters", on_delete=models.CASCADE)
58-
school_course = models.ForeignKey(SchoolCourse, related_name="rosters", on_delete=models.CASCADE)
64+
student = models.ForeignKey(
65+
Student, related_name="rosters", on_delete=models.CASCADE
66+
)
67+
school_course = models.ForeignKey(
68+
SchoolCourse, related_name="rosters", on_delete=models.CASCADE
69+
)
5970

6071
start_date = models.DateField()
6172
end_date = models.DateField()
@@ -64,4 +75,8 @@ class Roster(models.Model):
6475
deactivated_at = models.DateField(null=True, blank=True)
6576

6677
class Meta:
67-
constraints = [models.CheckConstraint(name="roster_start_before_end", check=Q(start_date__lt=F("end_date")))]
78+
constraints = [
79+
models.CheckConstraint(
80+
name="roster_start_before_end", check=Q(start_date__lt=F("end_date"))
81+
)
82+
]

styleguide_example/testing_examples/selectors/schools.py

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from typing import Optional
33

44
from django.core.exceptions import ValidationError
5-
from django.db.models.query import Q, QuerySet
5+
from django.db.models import Q, QuerySet
66

77
from styleguide_example.testing_examples.models import School, SchoolCourse
88

@@ -12,26 +12,39 @@
1212

1313

1414
def school_list_school_courses(
15-
*, school: School, start_date: Optional[date] = None, end_date: Optional[date] = None
15+
*,
16+
school: School,
17+
start_date: Optional[date] = None,
18+
end_date: Optional[date] = None,
1619
) -> QuerySet[SchoolCourse]:
1720
if start_date is None and end_date:
1821
raise ValidationError(SCHOOL_LIST_SCHOOL_COURSES_PROVIDE_START_DATE_MSG)
1922

2023
school_courses = school.school_courses.order_by("start_date")
2124

2225
if start_date and end_date:
23-
started_courses_Q = Q(start_date__lte=start_date, end_date__gte=start_date, end_date__lte=end_date)
26+
started_courses_Q = Q(
27+
start_date__lte=start_date, end_date__gte=start_date, end_date__lte=end_date
28+
)
2429
courses_in_period_q = Q(start_date__gte=start_date, end_date__lte=end_date)
25-
courses_wrapping_period_q = Q(start_date__lte=start_date, end_date__gte=end_date)
26-
future_course_q = Q(start_date__gte=start_date, start_date__lte=end_date, end_date__gte=end_date)
30+
courses_wrapping_period_q = Q(
31+
start_date__lte=start_date, end_date__gte=end_date
32+
)
33+
future_course_q = Q(
34+
start_date__gte=start_date, start_date__lte=end_date, end_date__gte=end_date
35+
)
2736

2837
return school_courses.filter(
29-
started_courses_Q | courses_in_period_q | courses_wrapping_period_q | future_course_q
38+
started_courses_Q
39+
| courses_in_period_q
40+
| courses_wrapping_period_q
41+
| future_course_q
3042
)
3143

3244
if start_date and end_date is None:
3345
return school_courses.filter(
34-
Q(start_date__gte=start_date) | Q(start_date__lte=start_date, end_date__gte=start_date)
46+
Q(start_date__gte=start_date)
47+
| Q(start_date__lte=start_date, end_date__gte=start_date)
3548
)
3649

3750
return school_courses

0 commit comments

Comments
 (0)