Skip to content

Commit a940891

Browse files
Rob Hudsonrobhudson
authored andcommitted
Add ruff check "FAST" and fix issues
1 parent 4f9f2a1 commit a940891

File tree

3 files changed

+32
-30
lines changed

3 files changed

+32
-30
lines changed

ctms/routers/contacts.py

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import json
22
from datetime import datetime
3-
from typing import Literal
3+
from typing import Annotated, Literal
44
from uuid import UUID, uuid4
55

66
from fastapi import APIRouter, Depends, HTTPException, Path, Request, Response
@@ -147,8 +147,8 @@ def get_bulk_contacts_by_timestamp_or_4xx(
147147
)
148148
def read_ctms_by_any_id(
149149
request: Request,
150-
db: Session = Depends(get_db),
151-
api_client: ApiClientSchema = Depends(get_enabled_api_client),
150+
db: Annotated[Session, Depends(get_db)],
151+
api_client: Annotated[ApiClientSchema, Depends(get_enabled_api_client)],
152152
ids=Depends(all_ids),
153153
):
154154
if not any(ids.values()):
@@ -170,9 +170,9 @@ def read_ctms_by_any_id(
170170
)
171171
def read_ctms_by_email_id(
172172
request: Request,
173-
email_id: UUID = Path(..., title="The Email ID"),
174-
db: Session = Depends(get_db),
175-
api_client: ApiClientSchema = Depends(get_enabled_api_client),
173+
email_id: Annotated[UUID, Path(..., title="The Email ID")],
174+
db: Annotated[Session, Depends(get_db)],
175+
api_client: Annotated[ApiClientSchema, Depends(get_enabled_api_client)],
176176
):
177177
resp = get_ctms_response_or_404(db, email_id)
178178
return resp
@@ -194,9 +194,9 @@ def create_ctms_contact(
194194
contact: ContactInSchema,
195195
request: Request,
196196
response: Response,
197-
db: Session = Depends(get_db),
198-
api_client: ApiClientSchema = Depends(get_enabled_api_client),
199-
content_json: dict | None = Depends(get_json),
197+
db: Annotated[Session, Depends(get_db)],
198+
api_client: Annotated[ApiClientSchema, Depends(get_enabled_api_client)],
199+
content_json: Annotated[dict | None, Depends(get_json)],
200200
):
201201
contact.email.email_id = contact.email.email_id or uuid4()
202202
email_id = contact.email.email_id
@@ -235,10 +235,10 @@ def create_or_update_ctms_contact(
235235
contact: ContactPutSchema,
236236
request: Request,
237237
response: Response,
238-
email_id: UUID = Path(..., title="The Email ID"),
239-
db: Session = Depends(get_db),
240-
api_client: ApiClientSchema = Depends(get_enabled_api_client),
241-
content_json: dict | None = Depends(get_json),
238+
email_id: Annotated[UUID, Path(..., title="The Email ID")],
239+
db: Annotated[Session, Depends(get_db)],
240+
api_client: Annotated[ApiClientSchema, Depends(get_enabled_api_client)],
241+
content_json: Annotated[dict | None, Depends(get_json)],
242242
):
243243
if contact.email.email_id:
244244
if contact.email.email_id != email_id:
@@ -279,10 +279,10 @@ def partial_update_ctms_contact(
279279
contact: ContactPatchSchema,
280280
request: Request,
281281
response: Response,
282-
email_id: UUID = Path(..., title="The Email ID"),
283-
db: Session = Depends(get_db),
284-
api_client: ApiClientSchema = Depends(get_enabled_api_client),
285-
content_json: dict | None = Depends(get_json),
282+
email_id: Annotated[UUID, Path(..., title="The Email ID")],
283+
db: Annotated[Session, Depends(get_db)],
284+
api_client: Annotated[ApiClientSchema, Depends(get_enabled_api_client)],
285+
content_json: Annotated[dict | None, Depends(get_json)],
286286
):
287287
if contact.email and contact.email.email_id and contact.email.email_id != email_id:
288288
raise HTTPException(
@@ -318,8 +318,8 @@ def partial_update_ctms_contact(
318318
)
319319
def delete_contact_by_primary_email(
320320
primary_email: str,
321-
db: Session = Depends(get_db),
322-
api_client: ApiClientSchema = Depends(get_enabled_api_client),
321+
db: Annotated[Session, Depends(get_db)],
322+
api_client: Annotated[ApiClientSchema, Depends(get_enabled_api_client)],
323323
):
324324
ids = all_ids(primary_email=primary_email.lower())
325325
contacts = get_contacts_by_any_id(db, **ids)
@@ -349,8 +349,8 @@ def read_ctms_in_bulk_by_timestamps_and_limit(
349349
limit: int | Literal[""] | None = None,
350350
after: str | None = None,
351351
mofo_relevant: bool | Literal[""] | None = None,
352-
db: Session = Depends(get_db),
353-
api_client: ApiClientSchema = Depends(get_enabled_api_client),
352+
db: Session = Depends(get_db), # noqa: FAST002, parameter without default
353+
api_client: ApiClientSchema = Depends(get_enabled_api_client), # noqa: FAST002, parameter without default
354354
):
355355
try:
356356
bulk_request = BulkRequestSchema(
@@ -377,8 +377,8 @@ def read_ctms_in_bulk_by_timestamps_and_limit(
377377
tags=["Private"],
378378
)
379379
def read_identities(
380-
db: Session = Depends(get_db),
381-
api_client: ApiClientSchema = Depends(get_enabled_api_client),
380+
db: Annotated[Session, Depends(get_db)],
381+
api_client: Annotated[ApiClientSchema, Depends(get_enabled_api_client)],
382382
ids=Depends(all_ids),
383383
):
384384
if not any(ids.values()):
@@ -399,9 +399,9 @@ def read_identities(
399399
tags=["Private"],
400400
)
401401
def read_identity(
402-
email_id: UUID = Path(..., title="The email ID"),
403-
db: Session = Depends(get_db),
404-
api_client: ApiClientSchema = Depends(get_enabled_api_client),
402+
email_id: Annotated[UUID, Path(..., title="The Email ID")],
403+
db: Annotated[Session, Depends(get_db)],
404+
api_client: Annotated[ApiClientSchema, Depends(get_enabled_api_client)],
405405
):
406406
contact = get_contact_or_404(db, email_id)
407407
return contact.as_identity_response()

ctms/routers/platform.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import logging
2+
from typing import Annotated
23

34
from dockerflow import checks as dockerflow_checks
45
from fastapi import APIRouter, Depends, HTTPException, Request, Response
@@ -47,9 +48,9 @@ def root():
4748
)
4849
def login(
4950
request: Request,
50-
db: Session = Depends(get_db),
51-
form_data: OAuth2ClientCredentialsRequestForm = Depends(),
52-
basic_credentials: HTTPBasicCredentials | None = Depends(token_scheme),
51+
db: Annotated[Session, Depends(get_db)],
52+
form_data: Annotated[OAuth2ClientCredentialsRequestForm, Depends()],
53+
basic_credentials: Annotated[HTTPBasicCredentials | None, Depends(token_scheme)],
5354
token_settings=Depends(get_token_settings),
5455
):
5556
auth_info = auth_info_context.get()
@@ -113,7 +114,7 @@ def database():
113114

114115

115116
@router.get("/__crash__", tags=["Platform"], include_in_schema=False)
116-
def crash(api_client: ApiClientSchema = Depends(get_enabled_api_client)):
117+
def crash(api_client: Annotated[ApiClientSchema, Depends(get_enabled_api_client)]):
117118
"""Raise an exception to test Sentry integration."""
118119
raise RuntimeError("Test exception handling")
119120

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ select = [
7575
"C4", # flake8-comprehensions errors
7676
"E", # pycodestyle errors
7777
"F", # pyflakes errors
78+
"FAST", # FastAPI
7879
"I", # import sorting
7980
"PL", # pylint errors
8081
"Q", # flake8-quotes errors

0 commit comments

Comments
 (0)