Skip to content

Commit

Permalink
Add basic typing information to module froide.foirequest.
Browse files Browse the repository at this point in the history
  • Loading branch information
missgreenwood committed Mar 18, 2022
1 parent 56ee290 commit bf20ac1
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions froide/foirequest/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from collections import Counter
from dataclasses import dataclass
from datetime import timedelta
from typing import Iterator, Optional
from typing import Generator, Iterator, Optional, Union

from django import forms
from django.conf import settings
Expand All @@ -30,6 +30,8 @@
)
from froide.publicbody.models import PublicBody

from .models.request import FoiRequest

MAX_ATTACHMENT_SIZE = settings.FROIDE_CONFIG["max_attachment_size"]
RECIPIENT_BLOCKLIST = settings.FROIDE_CONFIG.get("recipient_blocklist_regex", None)

Expand Down Expand Up @@ -159,8 +161,11 @@ def short_request_url(name, foirequest, message=None):


def redact_plaintext_with_request(
plaintext, foirequest, redact_greeting=False, redact_closing=False
):
plaintext: str,
foirequest: FoiRequest,
redact_greeting: bool = False,
redact_closing: bool = False,
) -> str:
replacements = get_secret_url_replacements()
user_replacements = foirequest.user.get_redactions()
return redact_plaintext(
Expand Down Expand Up @@ -444,7 +449,7 @@ def get_emails_from_message_headers(email_headers):
yield email


def possible_reply_addresses(foirequest):
def possible_reply_addresses(foirequest: FoiRequest) -> list:
options = []
for email_info in get_emails_from_request(foirequest, include_mediator=False):
if RECIPIENT_BLOCKLIST and RECIPIENT_BLOCKLIST.match(email_info.email):
Expand All @@ -460,11 +465,11 @@ def possible_reply_addresses(foirequest):


class MailAttachmentSizeChecker:
def __init__(self, generator, max_size=MAX_ATTACHMENT_SIZE):
def __init__(self, generator, max_size: int = MAX_ATTACHMENT_SIZE) -> None:
self.generator = generator
self.max_size = max_size

def __iter__(self):
def __iter__(self) -> Generator[Union[str, bytes], None, None]:
sum_bytes = 0
self.non_send_files = []
self.send_files = []
Expand Down

0 comments on commit bf20ac1

Please sign in to comment.