Skip to content
This repository was archived by the owner on Oct 2, 2021. It is now read-only.

Commit 7dc0ff9

Browse files
committed
Switch to mypy
This is a work-in-progress attempt at switching over to mypy as part of #85. There's still some work to be done (e.g. mypy ignore comments need to be added where appropriate) and I'm currently working with some local changes pyre's stubs, but I wanted to track the work being done.
1 parent 263bc47 commit 7dc0ff9

File tree

22 files changed

+16
-104
lines changed

22 files changed

+16
-104
lines changed

.flake8

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,5 @@ max-line-length = 80
55
max-complexity = 18
66
per-file-ignores =
77
src/awards/settings/dev.py: F405
8-
# TODO: Remove these once
9-
# https://github.com/facebook/pyre-check/pull/256,
10-
# https://github.com/facebook/pyre-check/pull/260,
11-
# https://github.com/facebook/pyre-check/pull/261, and
12-
# https://github.com/facebook/pyre-check/pull/262 can be used.
138
src/applications/forms.py: B950
14-
src/applications/migrations/0003_auto_20200507_0125.py: B950
15-
src/applications/models.py: B950
16-
src/applications/test_views.py: B950
17-
src/awards/urls.py: B950
18-
src/homepage/test_views.py: B950
19-
src/users/migrations/0001_initial.py: B950
20-
src/users/forms.py: B950
21-
src/users/models.py: B950
22-
src/users/views.py: B950
239
select = B,C,E,F,W,T4,B9

src/.pyre_configuration

Lines changed: 0 additions & 12 deletions
This file was deleted.

src/applications/forms.py

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ class FinancialAidApplicationForm(ApplicationForm):
1717
type = Application.Type.FINANCIAL_AID
1818

1919
travel_requested = forms.BooleanField(
20-
# pyre-ignore[16]: This is fixed by https://github.com/facebook/pyre-check/pull/262.
2120
label=_("Do you need assistance with travel?"),
2221
required=False,
2322
)
@@ -32,13 +31,9 @@ class Meta:
3231
"lodging_requested",
3332
)
3433
labels = {
35-
# pyre-ignore[16]: This is fixed by https://github.com/facebook/pyre-check/pull/262.
3634
"background": _("Tell us a little bit more about yourself"),
37-
# pyre-ignore[16]: This is fixed by https://github.com/facebook/pyre-check/pull/262.
3835
"lodging_requested": _("Do you need assistance with lodging?"),
39-
# pyre-ignore[16]: This is fixed by https://github.com/facebook/pyre-check/pull/262.
4036
"reason_to_attend": _("Why are you interested in attending PyGotham?"),
41-
# pyre-ignore[16]: This is fixed by https://github.com/facebook/pyre-check/pull/262.
4237
"travel_amount": _("What is the estimated cost (USD)?"),
4338
}
4439
widgets = {
@@ -51,20 +46,14 @@ def clean(self) -> Dict[str, Any]:
5146
travel_amount = cleaned_data.get("travel_amount") or 0
5247
if travel_amount < 0:
5348
raise forms.ValidationError(
54-
{
55-
# pyre-ignore[16]: This is fixed by https://github.com/facebook/pyre-check/pull/262.
56-
"travel_amount": _(
57-
"Your estimated travel costs cannot be negative."
58-
)
59-
}
49+
{"travel_amount": _("Your estimated travel costs cannot be negative.")}
6050
)
6151

6252
travel_requested = cleaned_data.get("travel_requested")
6353
if travel_requested:
6454
if not travel_amount:
6555
raise forms.ValidationError(
6656
{
67-
# pyre-ignore[16]: This is fixed by https://github.com/facebook/pyre-check/pull/262.
6857
"travel_amount": _(
6958
"Your estimated travel costs must be greater than $0.00."
7059
)
@@ -73,7 +62,6 @@ def clean(self) -> Dict[str, Any]:
7362
elif travel_amount:
7463
raise forms.ValidationError(
7564
{
76-
# pyre-ignore[16]: This is fixed by https://github.com/facebook/pyre-check/pull/262.
7765
"travel_requested": _(
7866
"You must request travel assistance before providing an estimated cost."
7967
)
@@ -83,7 +71,6 @@ def clean(self) -> Dict[str, Any]:
8371
return cleaned_data
8472

8573
def clean_lodging_requested(self) -> bool:
86-
# pyre-ignore[16]: This is fixed by https://github.com/facebook/pyre-check/pull/261.
8774
return bool(self.cleaned_data.get("lodging_requested"))
8875

8976

@@ -94,9 +81,7 @@ class Meta:
9481
model = Application
9582
fields = ("background", "reason_to_attend")
9683
labels = {
97-
# pyre-ignore[16]: This is fixed by https://github.com/facebook/pyre-check/pull/262.
9884
"background": _("Tell us a little bit about yourself"),
99-
# pyre-ignore[16]: This is fixed by https://github.com/facebook/pyre-check/pull/262.
10085
"reason_to_attend": _("Why are you interested in attending PyGotham?"),
10186
}
10287

src/applications/migrations/0003_auto_20200507_0125.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ class Migration(migrations.Migration):
1818
migrations.AddField(
1919
model_name="application",
2020
name="travel_amount",
21-
# pyre-ignore[16]: This is fixed by https://github.com/facebook/pyre-check/pull/260.
2221
field=models.DecimalField(
2322
blank=True, decimal_places=2, max_digits=10, null=True
2423
),

src/applications/models.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,44 +4,35 @@
44
from django.db import models
55
from django.utils.translation import ugettext_lazy as _
66

7-
# pyre-ignore[16]: This is fixed by https://github.com/facebook/pyre-check/pull/256.
87
User = get_user_model()
98

109

1110
class Application(models.Model):
12-
# pyre-ignore[11]: This is fixed by https://github.com/facebook/pyre-check/pull/256.
1311
class Status(models.TextChoices):
1412
PENDING = "pending"
1513

16-
# pyre-ignore[11]: This is fixed by https://github.com/facebook/pyre-check/pull/256.
1714
class Type(models.TextChoices):
1815
FINANCIAL_AID = "finaid"
1916
SCHOLARSHIP = "scholarship"
2017

21-
# pyre-ignore[16]: This is fixed by https://github.com/facebook/pyre-check/pull/256.
2218
applicant = models.ForeignKey(User, on_delete=models.DO_NOTHING)
2319
background = models.TextField(_("applicant background"))
2420
reason_to_attend = models.TextField(_("reason the applicant wishes to attend"))
2521
status = models.CharField(
2622
max_length=20,
27-
# pyre-ignore[16]: This is fixed by https://github.com/facebook/pyre-check/pull/256.
2823
choices=Status.choices,
2924
default=Status.PENDING,
3025
)
3126
type = models.CharField(
3227
max_length=11,
33-
# pyre-ignore[16]: This is fixed by https://github.com/facebook/pyre-check/pull/256.
3428
choices=Type.choices,
3529
default=Type.SCHOLARSHIP,
3630
)
37-
# pyre-ignore[16]: This is fixed by https://github.com/facebook/pyre-check/pull/260.
3831
travel_amount = models.DecimalField(
3932
max_digits=10, decimal_places=2, blank=True, null=True
4033
)
4134
lodging_requested = models.BooleanField(null=True)
4235

4336
def __str__(self) -> str:
44-
# pyre-ignore[19]: This is fixed by https://github.com/facebook/pyre-check/pull/256.
4537
type_ = Application.Type(self.type)
46-
# pyre-ignore[16]: This is fixed by https://github.com/facebook/pyre-check/pull/256.
4738
return f"{type_.label} application for {self.applicant}"

src/applications/test_forms.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ def test_financial_aid_lodging_requested_is_treated_as_boolean() -> None:
66

77
form = FinancialAidApplicationForm(other_fields)
88
assert form.is_valid()
9-
# pyre-ignore[16]: This is fixed by https://github.com/facebook/pyre-check/pull/261.
109
assert form.cleaned_data["lodging_requested"] is False
1110

1211

src/applications/test_views.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
from applications.views import apply
1212

1313

14-
# pyre-ignore[13]: Investigate type stubs for factory-boy.
1514
class ApplicationFactory(DjangoModelFactory):
1615
class Meta:
1716
model = Application
@@ -24,29 +23,25 @@ class Meta:
2423

2524
class UserFactory(DjangoModelFactory):
2625
class Meta:
27-
# pyre-ignore[16]: This is fixed by https://github.com/facebook/pyre-check/pull/256.
2826
model = get_user_model()
2927
django_get_or_create = ("email",)
3028

3129
email = "user@example.org"
3230

3331

3432
@pytest.mark.django_db
35-
# pyre-ignore[11]: This is fixed by https://github.com/facebook/pyre-check/pull/256.
3633
def test_that_one_of_form_type_and_pk_is_required_by_apply(client: Client) -> None:
3734
user = UserFactory()
3835
qs = get_query_string(user)
3936
client.get(f"/login/magic{qs}")
4037

4138
request = HttpRequest()
4239
request.user = user
43-
# pyre-ignore[16]: pyre doesn't think ExceptionInfo as an __enter__.
4440
with pytest.raises(Http404):
4541
apply(request, form_type=None, pk=None)
4642

4743

4844
@pytest.mark.django_db
49-
# pyre-ignore[11]: This is fixed by https://github.com/facebook/pyre-check/pull/256.
5045
def test_user_can_edit_their_application(client: Client) -> None:
5146
user = UserFactory()
5247
qs = get_query_string(user)
@@ -67,7 +62,6 @@ def test_user_can_edit_their_application(client: Client) -> None:
6762

6863

6964
@pytest.mark.django_db
70-
# pyre-ignore[11]: This is fixed by https://github.com/facebook/pyre-check/pull/256.
7165
def test_user_can_view_their_application(client: Client) -> None:
7266
user = UserFactory()
7367
qs = get_query_string(user)
@@ -80,7 +74,6 @@ def test_user_can_view_their_application(client: Client) -> None:
8074

8175

8276
@pytest.mark.django_db
83-
# pyre-ignore[11]: This is fixed by https://github.com/facebook/pyre-check/pull/256.
8477
def test_user_cant_view_someone_elses_application(client: Client) -> None:
8578
user = UserFactory()
8679
other = UserFactory(email=f"other+{user.email}")

src/applications/urls.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,15 @@
99
app_name = "applications"
1010

1111
urlpatterns = [
12-
# pyre-ignore[16]: This is fixed by https://github.com/facebook/pyre-check/pull/256.
1312
path("edit/<int:pk>", apply, name="edit"),
14-
# pyre-ignore[16]: This is fixed by https://github.com/facebook/pyre-check/pull/256.
1513
path(
1614
"financial-aid",
1715
apply,
1816
{"form_type": FinancialAidApplicationForm},
1917
name="financial_aid",
2018
),
21-
# pyre-ignore[16]: This is fixed by https://github.com/facebook/pyre-check/pull/256.
2219
path(
2320
"ticket", apply, {"form_type": ScholarshipApplicationForm}, name="scholarship"
2421
),
25-
# pyre-ignore[16]: This is fixed by https://github.com/facebook/pyre-check/pull/256.
2622
path("view/<int:pk>", view, name="view"),
2723
]

src/awards/settings/base.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
from __future__ import annotations
2+
13
import os
4+
from typing import List
25

3-
from decouple import config
6+
from decouple import config # type: ignore[import]
47

58
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
69
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
@@ -9,7 +12,7 @@
912
# Quick-start development settings - unsuitable for production
1013
# See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/
1114

12-
ALLOWED_HOSTS = []
15+
ALLOWED_HOSTS: List[str] = []
1316

1417

1518
# Application definition
@@ -77,7 +80,7 @@
7780
# https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators
7881

7982
# Password-based login isn't supported.
80-
AUTH_PASSWORD_VALIDATORS = []
83+
AUTH_PASSWORD_VALIDATORS: List[str] = []
8184

8285
AUTH_USER_MODEL = "users.User"
8386

src/awards/settings/prod.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from decouple import config
1+
from decouple import config # type: ignore[import]
22

33
from awards.settings.base import * # NOQA
44

0 commit comments

Comments
 (0)