Skip to content

Commit

Permalink
chore: fix mypy errors (#197)
Browse files Browse the repository at this point in the history
  • Loading branch information
fchancel committed Jul 18, 2023
1 parent c15d24e commit d74266d
Show file tree
Hide file tree
Showing 6 changed files with 243 additions and 226 deletions.
22 changes: 14 additions & 8 deletions fastapi_mail/email_utils/email_check.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import inspect
from abc import ABC, abstractmethod
from typing import Any, Dict, List, Set, Union
from typing import Any, Dict, List, Optional, Set, Union

import dns.exception
import dns.resolver
Expand Down Expand Up @@ -86,14 +86,14 @@ class DefaultChecker(AbstractEmailChecker):

def __init__(
self,
source: str = None,
db_provider: str = None,
source: Optional[str] = None,
db_provider: Optional[str] = None,
*,
redis_host: str = "localhost",
redis_port: int = 6379,
redis_db: int = 0,
redis_password: str = None,
username: str = None,
redis_password: Optional[str] = None,
username: Optional[str] = None,
**options: dict,
):

Expand Down Expand Up @@ -294,19 +294,25 @@ async def check_mx_record(
async def blocked_email_count(self) -> int:
"""count all blocked emails in redis"""
if self.redis_enabled:
return await self.redis_client.get("email_counter")
result = await self.redis_client.get("email_counter")
if result is not None:
return result
return len(self.BLOCKED_ADDRESSES)

async def blocked_domain_count(self) -> int:
"""count all blocked domains in redis"""
if self.redis_enabled:
return await self.redis_client.get("domain_counter")
result = await self.redis_client.get("domain_counter")
if result is not None:
return result
return len(self.BLOCKED_DOMAINS)

async def temp_email_count(self) -> int:
"""count all temporary emails in redis"""
if self.redis_enabled:
return await self.redis_client.get("temp_counter")
result = await self.redis_client.get("temp_counter")
if result is not None:
return result
return len(self.TEMP_EMAIL_DOMAINS)

async def close_connections(self) -> bool:
Expand Down
6 changes: 3 additions & 3 deletions fastapi_mail/fastmail.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from contextlib import contextmanager
from email.message import EmailMessage, Message
from typing import Any, Dict, Union
from typing import Any, Dict, Optional, Union

import blinker
from jinja2 import Environment, Template
Expand Down Expand Up @@ -65,7 +65,7 @@ def check_data(data: Union[Dict[Any, Any], str, None]) -> Dict[Any, Any]:
return data

async def __prepare_message(
self, message: MessageSchema, template: Template = None
self, message: MessageSchema, template: Optional[Template] = None
) -> Union[EmailMessage, Message]:
if template and message.template_body is not None:
message.template_body = await self.__template_message_builder(
Expand All @@ -91,7 +91,7 @@ async def __sender(self) -> Union[EmailStr, str]:
return sender

async def send_message(
self, message: MessageSchema, template_name: str = None
self, message: MessageSchema, template_name: Optional[str] = None
) -> None:
if not isinstance(message, MessageSchema):
raise PydanticClassRequired(
Expand Down
6 changes: 4 additions & 2 deletions fastapi_mail/msg.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.utils import formatdate, make_msgid
from typing import Any, Union
from typing import Any, Optional, Union

from .schemas import MessageType, MultipartSubtypeEnum

Expand Down Expand Up @@ -107,7 +107,9 @@ def attach_alternative(self, message: MIMEMultipart) -> MIMEMultipart:
message.attach(tmpmsg)
return message

async def _message(self, sender: str = None) -> Union[EmailMessage, Message]:
async def _message(
self, sender: Optional[str] = None
) -> Union[EmailMessage, Message]:
"""
Creates the email message
"""
Expand Down
Loading

0 comments on commit d74266d

Please sign in to comment.