Skip to content

Commit a23b725

Browse files
chore: update typehints via __future__.annotations
1 parent 3fd1236 commit a23b725

File tree

15 files changed

+141
-112
lines changed

15 files changed

+141
-112
lines changed

intranet/apps/eighth/forms/admin/activities.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
from __future__ import annotations
2+
13
import logging
2-
from typing import List # noqa
34

45
from django import forms, http
56
from django.contrib.auth import get_user_model
@@ -11,7 +12,7 @@
1112

1213

1314
class ActivityDisplayField(forms.ModelChoiceField):
14-
cancelled_acts = None # type: List[EighthActivity]
15+
cancelled_acts: list[EighthActivity] | None = None
1516

1617
def __init__(self, *args, **kwargs):
1718
if "block" in kwargs:

intranet/apps/eighth/models.py

+33-33
Large diffs are not rendered by default.

intranet/apps/eighth/tasks.py

+11-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import calendar
24
import datetime
35
from typing import Collection
@@ -20,7 +22,9 @@
2022

2123
@shared_task
2224
def room_changed_single_email(
23-
sched_act: EighthScheduledActivity, old_rooms: Collection[EighthRoom], new_rooms: Collection[EighthRoom] # pylint: disable=unsubscriptable-object
25+
sched_act: EighthScheduledActivity,
26+
old_rooms: Collection[EighthRoom],
27+
new_rooms: Collection[EighthRoom], # pylint: disable=unsubscriptable-object
2428
): # pylint: disable=unsubscriptable-object
2529
"""Notifies all the users signed up for the given EighthScheduledActivity that it is changing rooms.
2630
@@ -70,7 +74,9 @@ def room_changed_single_email(
7074

7175
@shared_task
7276
def transferred_activity_email(
73-
dest_act: EighthScheduledActivity, source_act: EighthScheduledActivity, duplicate_students # pylint: disable=unsubscriptable-object
77+
dest_act: EighthScheduledActivity,
78+
source_act: EighthScheduledActivity,
79+
duplicate_students, # pylint: disable=unsubscriptable-object
7480
): # pylint: disable=unsubscriptable-object
7581
"""Notifies all the users already signed up for an EighthScheduledActivity that they have been transferred into a new activity.
7682
@@ -116,7 +122,9 @@ def transferred_activity_email(
116122

117123
@shared_task
118124
def room_changed_activity_email(
119-
act: EighthActivity, old_rooms: Collection[EighthRoom], new_rooms: Collection[EighthRoom] # pylint: disable=unsubscriptable-object
125+
act: EighthActivity,
126+
old_rooms: Collection[EighthRoom],
127+
new_rooms: Collection[EighthRoom], # pylint: disable=unsubscriptable-object
120128
): # pylint: disable=unsubscriptable-object
121129
"""Notifies all the users signed up for the given EighthActivity on the blocks for which the room
122130
list is not overriden that it is changing rooms.

intranet/apps/eighth/views/admin/groups.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
from __future__ import annotations
2+
13
import csv
24
import logging
35
import re
4-
from typing import List, Optional
56

67
from cacheops import invalidate_model, invalidate_obj
78
from formtools.wizard.views import SessionWizardView
@@ -156,7 +157,7 @@ def get_file_string(fileobj):
156157
return filetext
157158

158159

159-
def get_user_info(key: str, val) -> Optional[List[User]]:
160+
def get_user_info(key: str, val) -> list[User] | None:
160161
if key in ["username", "id"]:
161162
try:
162163
u = get_user_model().objects.filter(**{key: val})
@@ -200,7 +201,7 @@ def handle_group_input(filetext: str):
200201
return find_users_input(lines)
201202

202203

203-
def find_users_input(lines: List[str]):
204+
def find_users_input(lines: list[str]):
204205
sure_users = []
205206
unsure_users = []
206207
for line in lines:
@@ -487,7 +488,7 @@ def eighth_admin_signup_group_action(request, group_id, schact_id):
487488
)
488489

489490

490-
def eighth_admin_perform_group_signup(*, group_id: int, schact_id: int, request: Optional[http.HttpRequest], skip_users: set):
491+
def eighth_admin_perform_group_signup(*, group_id: int, schact_id: int, request: http.HttpRequest | None, skip_users: set):
491492
"""Performs sign up of all users in a specific group up for a
492493
specific scheduled activity.
493494

intranet/apps/eighth/views/admin/hybrid.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
from __future__ import annotations
2+
13
import logging
2-
from typing import Optional
34

45
from formtools.wizard.views import SessionWizardView
56

@@ -217,7 +218,7 @@ def eighth_admin_signup_group_action_hybrid(request, group_id, schact_virtual_id
217218
)
218219

219220

220-
def eighth_admin_perform_group_signup(*, group_id: int, schact_virtual_id: int, schact_person_id: int, request: Optional[http.HttpRequest]):
221+
def eighth_admin_perform_group_signup(*, group_id: int, schact_virtual_id: int, schact_person_id: int, request: http.HttpRequest | None):
221222
"""Performs sign up of all users in a specific group up for a
222223
specific scheduled activity.
223224

intranet/apps/features/helpers.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
from typing import Optional
1+
from __future__ import annotations
22

33

4-
def get_feature_context(request) -> Optional[str]:
4+
def get_feature_context(request) -> str | None:
55
"""Given a Django request, returns the 'context' that should be used to select feature
66
announcements to display (one of ``dashboard``, ``login``, ``eighth_signup``, or ``None``).
77

intranet/apps/notifications/emails.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
from __future__ import annotations
2+
13
import logging
2-
from typing import Collection, Mapping
4+
from typing import Mapping, MutableSequence
35

46
from django.conf import settings
57
from django.core.mail import EmailMultiAlternatives
@@ -13,11 +15,11 @@ def email_send(
1315
html_template: str,
1416
data: Mapping[str, object],
1517
subject: str,
16-
emails: Collection[str], # pylint: disable=unsubscriptable-object
17-
headers: Mapping[str, str] = None, # pylint: disable=unsubscriptable-object
18+
emails: MutableSequence[str],
19+
headers: Mapping[str, str] | None = None,
1820
bcc: bool = False,
1921
*,
20-
custom_logger: logging.Logger = None,
22+
custom_logger: logging.Logger | None = None,
2123
) -> EmailMultiAlternatives:
2224
"""Send an HTML/Plaintext email with the following fields.
2325
If we are not in production and settings.FORCE_EMAIL_SEND is not set, does not actually send the email

intranet/apps/printing/views.py

+9-7
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
from __future__ import annotations
2+
13
import logging
24
import math
35
import os
46
import re
57
import subprocess
68
import tempfile
79
from io import BytesIO
8-
from typing import Dict, Optional
910

1011
import magic
1112
from sentry_sdk import add_breadcrumb, capture_exception
@@ -32,14 +33,15 @@ class InvalidInputPrintingError(Exception):
3233
"""An error occurred while printing, but it was due to invalid input from the user and is not worthy of a ``CRITICAL`` log message."""
3334

3435

35-
def get_printers() -> Dict[str, str]:
36+
def get_printers() -> dict[str, str] | list:
3637
"""Returns a dictionary mapping name:description for available printers.
3738
3839
This requires that a CUPS client be configured on the server.
3940
Otherwise, this returns an empty dictionary.
4041
4142
Returns:
42-
A dictionary mapping name:description for available printers.
43+
A dictionary mapping name:description for available printers, or
44+
an empty list if cups isn't installed or lpstat fails
4345
"""
4446

4547
key = "printing:printers"
@@ -88,7 +90,7 @@ def get_printers() -> Dict[str, str]:
8890
return printers
8991

9092

91-
def convert_soffice(tmpfile_name: str) -> Optional[str]:
93+
def convert_soffice(tmpfile_name: str) -> str | None:
9294
"""Converts a doc or docx to a PDF with soffice.
9395
9496
Args:
@@ -119,7 +121,7 @@ def convert_soffice(tmpfile_name: str) -> Optional[str]:
119121
return None
120122

121123

122-
def convert_pdf(tmpfile_name: str, cmdname: str = "ps2pdf") -> Optional[str]:
124+
def convert_pdf(tmpfile_name: str, cmdname: str = "ps2pdf") -> str | None:
123125
new_name = "{}.pdf".format(tmpfile_name)
124126
try:
125127
output = subprocess.check_output([cmdname, tmpfile_name, new_name], stderr=subprocess.STDOUT, universal_newlines=True)
@@ -181,7 +183,7 @@ def get_mimetype(tmpfile_name: str) -> str:
181183
return mimetype
182184

183185

184-
def convert_file(tmpfile_name: str, orig_fname: str) -> Optional[str]:
186+
def convert_file(tmpfile_name: str, orig_fname: str) -> str | None:
185187
detected = get_mimetype(tmpfile_name)
186188

187189
add_breadcrumb(category="printing", message="Detected file type {}".format(detected), level="debug")
@@ -213,7 +215,7 @@ def convert_file(tmpfile_name: str, orig_fname: str) -> Optional[str]:
213215
raise InvalidInputPrintingError("Invalid file type {}".format(detected))
214216

215217

216-
def check_page_range(page_range: str, max_pages: int) -> Optional[int]:
218+
def check_page_range(page_range: str, max_pages: int) -> int | None:
217219
"""Returns the number of pages included in the range, or None if it is an invalid range.
218220
219221
Args:

intranet/apps/signage/views.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
from __future__ import annotations
2+
13
import datetime
24
import logging
3-
from typing import Optional
45

56
from django import http
67
from django.conf import settings
@@ -20,7 +21,7 @@
2021
logger = logging.getLogger(__name__)
2122

2223

23-
def check_internal_ip(request) -> Optional[HttpResponse]:
24+
def check_internal_ip(request) -> HttpResponse | None:
2425
"""
2526
A method to determine if a request is allowed to load a signage page.
2627

intranet/apps/templatetags/paginate.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import List, Union
1+
from __future__ import annotations
22

33
from django import template
44

@@ -13,8 +13,8 @@ def query_transform(request, **kwargs):
1313
return query.urlencode()
1414

1515

16-
@register.filter # TODO: replace return type with list[int | None]
17-
def page_list(paginator, current_page) -> List[Union[int, None]]:
16+
@register.filter
17+
def page_list(paginator, current_page) -> list[int | None]:
1818
"""Pagination
1919
2020
If there is a ``None`` in the output, it should be replaced

0 commit comments

Comments
 (0)