Skip to content

Commit

Permalink
chore: use Union instead of | notation
Browse files Browse the repository at this point in the history
  • Loading branch information
drish committed Apr 17, 2024
1 parent 537c261 commit 11f14cc
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 30 deletions.
4 changes: 2 additions & 2 deletions resend/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
from .version import get_version

# Config vars
api_key: str | None = os.environ.get("RESEND_API_KEY")
api_url: str | None = os.environ.get("RESEND_API_URL", "https://api.resend.com")
api_key = os.environ.get("RESEND_API_KEY")
api_url = os.environ.get("RESEND_API_URL", "https://api.resend.com")

# API resources
from .emails._emails import Emails # noqa
Expand Down
10 changes: 5 additions & 5 deletions resend/emails/_email.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from typing import List
from typing import List, Union


class Email:
id: str
"""
The Email ID.
"""
to: List[str] | str
to: Union[List[str], str]
"""
List of email addresses to send the email to.
"""
Expand All @@ -31,15 +31,15 @@ class Email:
"""
The text content of the email.
"""
bcc: List[str] | str
bcc: Union[List[str], str]
"""
Bcc
"""
cc: List[str] | str
cc: Union[List[str], str]
"""
Cc
"""
reply_to: List[str] | str
reply_to: Union[List[str], str]
"""
Reply to
"""
Expand Down
10 changes: 5 additions & 5 deletions resend/emails/_emails.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Dict, List, cast
from typing import Any, Dict, List, Union, cast

from typing_extensions import NotRequired, TypedDict

Expand All @@ -15,23 +15,23 @@ class SendParams(TypedDict):
The email address of the sender.
"from" is a reserved keyword in python, so we use "sender" here instead
"""
to: str | List[str]
to: Union[str, List[str]]
"""
List of email addresses to send the email to.
"""
subject: str
"""
The subject of the email.
"""
bcc: NotRequired[List[str] | str]
bcc: NotRequired[Union[List[str], str]]
"""
Bcc
"""
cc: NotRequired[List[str] | str]
cc: NotRequired[Union[List[str], str]]
"""
Cc
"""
reply_to: NotRequired[List[str] | str]
reply_to: NotRequired[Union[List[str], str]]
"""
Reply to
"""
Expand Down
24 changes: 6 additions & 18 deletions resend/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class ResendError(Exception):

def __init__(
self,
code: str | int,
code: str,
error_type: str,
message: str,
suggested_action: str,
Expand All @@ -45,7 +45,7 @@ def __init__(
self,
message: str,
error_type: str,
code: str | int,
code: str,
):
suggested_action = """Include the following header
Authorization: Bearer YOUR_API_KEY in the request."""
Expand All @@ -68,7 +68,7 @@ def __init__(
self,
message: str,
error_type: str,
code: str | int,
code: str,
):
suggested_action = """Generate a new API key in the dashboard."""

Expand All @@ -88,7 +88,7 @@ def __init__(
self,
message: str,
error_type: str,
code: str | int,
code: str,
):
default_message = """
The request body is missing one or more required fields."""
Expand All @@ -101,7 +101,7 @@ def __init__(

ResendError.__init__(
self,
code=code or 400,
code=code or "400",
message=message,
suggested_action=suggested_action,
error_type=error_type,
Expand Down Expand Up @@ -162,19 +162,7 @@ def __init__(


# Dict with error code -> error type mapping
ERRORS: Dict[
str,
Dict[
str,
type[
ValidationError
| MissingApiKeyError
| MissingRequiredFieldsError
| InvalidApiKeyError
| ApplicationError
],
],
] = {
ERRORS: Dict = {
"400": {"validation_error": ValidationError},
"422": {"missing_required_fields": MissingRequiredFieldsError},
"401": {"missing_api_key": MissingApiKeyError},
Expand Down

0 comments on commit 11f14cc

Please sign in to comment.