Skip to content

Commit f2e67d2

Browse files
committed
chore: naming
1 parent fa5a831 commit f2e67d2

4 files changed

Lines changed: 31 additions & 41 deletions

File tree

examples/with_headers.py

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -18,35 +18,17 @@
1818
"html": "<strong>Hello, world!</strong>",
1919
}
2020

21-
print("=" * 60)
22-
print("Example 1: Without type annotations")
23-
print("=" * 60)
21+
resp: resend.Emails.SendResponse = resend.Emails.send(params)
22+
print(f"Email sent! ID: {resp['id']}")
2423

25-
response = resend.Emails.send(params)
26-
print(f"Email sent! ID: {response['id']}")
27-
print(f"Request ID: {response['headers'].get('x-request-id')}")
28-
print(f"Rate limit: {response['headers'].get('x-ratelimit-limit')}")
29-
print(f"Rate limit remaining: {response['headers'].get('x-ratelimit-remaining')}")
30-
print(f"Rate limit reset: {response['headers'].get('x-ratelimit-reset')}")
24+
if "headers" in resp:
25+
print(f"Request ID: {resp['headers'].get('x-request-id')}")
26+
print(f"Rate limit: {resp['headers'].get('x-ratelimit-limit')}")
27+
print(f"Rate limit remaining: {resp['headers'].get('x-ratelimit-remaining')}")
28+
print(f"Rate limit reset: {resp['headers'].get('x-ratelimit-reset')}")
3129

32-
print("\n" + "=" * 60)
33-
print("Example 2: With type annotations")
34-
print("=" * 60)
35-
36-
typed_response: resend.Emails.SendResponse = resend.Emails.send(params)
37-
print(f"Email sent! ID: {typed_response['id']}")
38-
39-
if "headers" in typed_response:
40-
print(f"Request ID: {typed_response['headers'].get('x-request-id')}")
41-
print(f"Rate limit: {typed_response['headers'].get('x-ratelimit-limit')}")
42-
print(
43-
f"Rate limit remaining: {typed_response['headers'].get('x-ratelimit-remaining')}"
44-
)
45-
print(f"Rate limit reset: {typed_response['headers'].get('x-ratelimit-reset')}")
46-
47-
print("\n" + "=" * 60)
30+
print("\n")
4831
print("Example 3: Rate limit tracking")
49-
print("=" * 60)
5032

5133

5234
def send_with_rate_limit_check(params: resend.Emails.SendParams) -> str:
@@ -61,7 +43,7 @@ def send_with_rate_limit_check(params: resend.Emails.SendParams) -> str:
6143
if remaining and limit:
6244
print(f"Rate limit usage: {int(limit) - int(remaining)}/{limit}")
6345
if int(remaining) < 10:
64-
print("⚠️ Warning: Approaching rate limit!")
46+
print("Warning: Approaching rate limit!")
6547

6648
return response["id"]
6749

resend/exceptions.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,10 @@ def raise_for_code_and_type(
249249
# Handle the case where the error might be unknown
250250
if error is None:
251251
raise ResendError(
252-
code=code, message=message, error_type=error_type, suggested_action="",
252+
code=code,
253+
message=message,
254+
error_type=error_type,
255+
suggested_action="",
253256
headers=headers,
254257
)
255258

@@ -265,7 +268,10 @@ def raise_for_code_and_type(
265268
)
266269
# defaults to ResendError if finally can't find error type
267270
raise ResendError(
268-
code=code, message=message, error_type=error_type, suggested_action="",
271+
code=code,
272+
message=message,
273+
error_type=error_type,
274+
suggested_action="",
269275
headers=headers,
270276
)
271277

tests/exceptions_test.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ def test_headers_passed_to_known_error(self) -> None:
7070
}
7171
with pytest.raises(RateLimitError) as e:
7272
raise_for_code_and_type(
73-
429, "rate_limit_exceeded", "Rate limit exceeded",
73+
429,
74+
"rate_limit_exceeded",
75+
"Rate limit exceeded",
7476
headers=headers,
7577
)
7678
assert e.value.headers == headers
@@ -93,14 +95,20 @@ def test_headers_on_validation_error(self) -> None:
9395
headers = {"x-request-id": "req_789"}
9496
with pytest.raises(ValidationError) as e:
9597
raise_for_code_and_type(
96-
400, "validation_error", "err", headers=headers,
98+
400,
99+
"validation_error",
100+
"err",
101+
headers=headers,
97102
)
98103
assert e.value.headers == headers
99104

100105
def test_headers_on_application_error(self) -> None:
101106
headers = {"x-request-id": "req_abc"}
102107
with pytest.raises(ApplicationError) as e:
103108
raise_for_code_and_type(
104-
500, "application_error", "err", headers=headers,
109+
500,
110+
"application_error",
111+
"err",
112+
headers=headers,
105113
)
106114
assert e.value.headers == headers

tests/response_test.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ def test_list_response_supports_dict_access(self) -> None:
2323
}
2424
)
2525

26-
attachments = resend.Emails.Receiving.Attachments.list(
27-
email_id="test-email-id"
28-
)
26+
attachments = resend.Emails.Receiving.Attachments.list(email_id="test-email-id")
2927
assert attachments["object"] == "list"
3028
assert attachments["has_more"] is False
3129
assert len(attachments["data"]) == 1
@@ -48,9 +46,7 @@ def test_list_response_supports_attribute_access(self) -> None:
4846
}
4947
)
5048

51-
attachments = resend.Emails.Receiving.Attachments.list(
52-
email_id="test-email-id"
53-
)
49+
attachments = resend.Emails.Receiving.Attachments.list(email_id="test-email-id")
5450
assert attachments.object == "list" # type: ignore[attr-defined]
5551
assert attachments.has_more is False # type: ignore[attr-defined]
5652
assert len(attachments.data) == 1 # type: ignore[attr-defined]
@@ -65,9 +61,7 @@ def test_attribute_access_raises_for_missing_key(self) -> None:
6561
}
6662
)
6763

68-
attachments = resend.Emails.Receiving.Attachments.list(
69-
email_id="test-email-id"
70-
)
64+
attachments = resend.Emails.Receiving.Attachments.list(email_id="test-email-id")
7165
with self.assertRaises(AttributeError):
7266
_ = attachments.nonexistent # type: ignore[attr-defined]
7367

0 commit comments

Comments
 (0)