Skip to content

Commit cb9ce93

Browse files
Ruff 0.11.8 (#697)
### Description Bump Ruff. Enable new rules
1 parent 3394d83 commit cb9ce93

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+177
-273
lines changed

app/core/auth/endpoints_auth.py

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ async def token(
442442
request_id=request_id,
443443
)
444444

445-
elif tokenreq.grant_type == "refresh_token":
445+
if tokenreq.grant_type == "refresh_token":
446446
return await refresh_token_grant(
447447
db=db,
448448
settings=settings,
@@ -451,15 +451,14 @@ async def token(
451451
request_id=request_id,
452452
)
453453

454-
else:
455-
hyperion_access_logger.warning(
456-
f"Token: Unsupported grant_type, received {tokenreq.grant_type} ({request_id})",
457-
)
458-
raise AuthHTTPException(
459-
status_code=400,
460-
error="unsupported_grant_type",
461-
error_description=f"{tokenreq.grant_type} is not supported",
462-
)
454+
hyperion_access_logger.warning(
455+
f"Token: Unsupported grant_type, received {tokenreq.grant_type} ({request_id})",
456+
)
457+
raise AuthHTTPException(
458+
status_code=400,
459+
error="unsupported_grant_type",
460+
error_description=f"{tokenreq.grant_type} is not supported",
461+
)
463462

464463

465464
async def authorization_code_grant(
@@ -708,7 +707,7 @@ async def refresh_token_grant(
708707
error="invalid_request",
709708
error_description="Invalid refresh token",
710709
)
711-
elif db_refresh_token.revoked_on is not None:
710+
if db_refresh_token.revoked_on is not None:
712711
# If the client tries to use a revoked refresh_token, we want to revoke all other refresh tokens from this client and user
713712
await cruds_auth.revoke_refresh_token_by_client_and_user_id(
714713
db=db,
@@ -762,7 +761,7 @@ async def refresh_token_grant(
762761
)
763762

764763
# If the auth provider expects to use a client secret, we don't use PKCE
765-
elif auth_client.secret is not None:
764+
if auth_client.secret is not None:
766765
# We need to check the correct client_secret was provided
767766
if auth_client.secret != tokenreq.client_secret:
768767
hyperion_access_logger.warning(
@@ -919,16 +918,14 @@ async def create_response_body(
919918
access_token = create_access_token(data=access_token_data, settings=settings)
920919

921920
# We create an OAuth response, with oidc specific elements if required
922-
response_body = schemas_auth.TokenResponse(
921+
return schemas_auth.TokenResponse(
923922
access_token=access_token,
924923
expires_in=settings.ACCESS_TOKEN_EXPIRE_MINUTES * 60, # in seconds
925924
scope=granted_scopes,
926925
refresh_token=refresh_token,
927926
id_token=id_token,
928927
)
929928

930-
return response_body
931-
932929

933930
@router.post(
934931
"/auth/introspect",

app/core/auth/schemas_auth.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Schemas file for endpoint /auth"""
22

33
from datetime import datetime
4+
from typing import Literal
45

56
from fastapi import Form
67
from pydantic import BaseModel, field_validator
@@ -145,7 +146,7 @@ class config:
145146

146147
class TokenResponse(BaseModel):
147148
access_token: str
148-
token_type: str = "bearer"
149+
token_type: Literal["bearer"] = "bearer" # noqa: S105
149150
expires_in: int = 1800
150151
scope: str = ""
151152
refresh_token: str

app/core/core_endpoints/endpoints_core.py

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -251,26 +251,22 @@ async def add_module_visibility(
251251
root=module_visibility.root,
252252
allowed_group_id=module_visibility.allowed_group_id,
253253
)
254-
try:
255-
return await cruds_core.create_module_group_visibility(
256-
module_visibility=module_group_visibility_db,
257-
db=db,
258-
)
259-
except ValueError as error:
260-
raise HTTPException(status_code=400, detail=str(error))
254+
255+
await cruds_core.create_module_group_visibility(
256+
module_visibility=module_group_visibility_db,
257+
db=db,
258+
)
261259

262260
if module_visibility.allowed_account_type is not None:
263261
module_account_visibility_db = models_core.ModuleAccountTypeVisibility(
264262
root=module_visibility.root,
265263
allowed_account_type=module_visibility.allowed_account_type,
266264
)
267-
try:
268-
return await cruds_core.create_module_account_type_visibility(
269-
module_visibility=module_account_visibility_db,
270-
db=db,
271-
)
272-
except ValueError as error:
273-
raise HTTPException(status_code=400, detail=str(error))
265+
266+
await cruds_core.create_module_account_type_visibility(
267+
module_visibility=module_account_visibility_db,
268+
db=db,
269+
)
274270

275271

276272
@router.delete("/module-visibility/{root}/groups/{group_id}", status_code=204)

app/core/google_api/google_api.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,12 @@ def _get_flow(self, settings: Settings) -> Flow:
5656
# "redirect_uris": [""],
5757
},
5858
}
59-
flow = Flow.from_client_config(
59+
return Flow.from_client_config(
6060
client_config,
6161
GoogleAPI.SCOPES,
6262
redirect_uri=settings.CLIENT_URL + "google-api/oauth2callback",
6363
)
6464

65-
return flow
66-
6765
async def _start_authentication(
6866
self,
6967
db: AsyncSession,

app/core/groups/endpoints_groups.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ async def read_groups(
4545
Return all groups from database as a list of dictionaries
4646
"""
4747

48-
groups = await cruds_groups.get_groups(db)
49-
return groups
48+
return await cruds_groups.get_groups(db)
5049

5150

5251
@router.get(

app/core/groups/schemas_groups.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,6 @@ class CoreMembershipDelete(BaseModel):
7070

7171

7272
# Importing here to avoid circular imports
73-
from app.core.users.schemas_users import CoreUserSimple # noqa: E402, TCH001
73+
from app.core.users.schemas_users import CoreUserSimple # noqa: E402, TC001
7474

7575
CoreGroup.model_rebuild()

app/core/memberships/endpoints_memberships.py

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ async def read_associations_memberships(
4141
Return all memberships from database as a list of dictionaries
4242
"""
4343

44-
memberships = await cruds_memberships.get_association_memberships(db)
45-
return memberships
44+
return await cruds_memberships.get_association_memberships(db)
4645

4746

4847
@router.get(
@@ -82,19 +81,15 @@ async def read_association_membership(
8281
detail="User is not allowed to access this membership",
8382
)
8483

85-
db_user_memberships = (
86-
await cruds_memberships.get_user_memberships_by_association_membership_id(
87-
db=db,
88-
association_membership_id=association_membership_id,
89-
minimal_start_date=minimalStartDate,
90-
maximal_start_date=maximalStartDate,
91-
minimal_end_date=minimalEndDate,
92-
maximal_end_date=maximalEndDate,
93-
)
84+
return await cruds_memberships.get_user_memberships_by_association_membership_id(
85+
db=db,
86+
association_membership_id=association_membership_id,
87+
minimal_start_date=minimalStartDate,
88+
maximal_start_date=maximalStartDate,
89+
minimal_end_date=minimalEndDate,
90+
maximal_end_date=maximalEndDate,
9491
)
9592

96-
return db_user_memberships
97-
9893

9994
@router.post(
10095
"/memberships/",
@@ -256,11 +251,10 @@ async def read_user_memberships(
256251
detail="User is not allowed to access other users' memberships",
257252
)
258253

259-
memberships = await cruds_memberships.get_user_memberships_by_user_id(
254+
return await cruds_memberships.get_user_memberships_by_user_id(
260255
db,
261256
user_id,
262257
)
263-
return memberships
264258

265259

266260
@router.get(
@@ -280,12 +274,11 @@ async def read_user_association_membership_history(
280274
**This endpoint is only usable by administrators**
281275
"""
282276

283-
memberships = await cruds_memberships.get_user_memberships_by_user_id_and_association_membership_id(
277+
return await cruds_memberships.get_user_memberships_by_user_id_and_association_membership_id(
284278
db,
285279
user_id,
286280
association_membership_id,
287281
)
288-
return memberships
289282

290283

291284
@router.post(

app/core/myeclpay/endpoints_myeclpay.py

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,10 @@ async def get_structures(
9494
"""
9595
Get all structures.
9696
"""
97-
structures = await cruds_myeclpay.get_structures(
97+
return await cruds_myeclpay.get_structures(
9898
db=db,
9999
)
100100

101-
return structures
102-
103101

104102
@router.post(
105103
"/myeclpay/structures",
@@ -848,13 +846,11 @@ async def get_store_sellers(
848846
detail="User does not have the permission to manage sellers",
849847
)
850848

851-
sellers = await cruds_myeclpay.get_sellers_by_store_id(
849+
return await cruds_myeclpay.get_sellers_by_store_id(
852850
store_id=store_id,
853851
db=db,
854852
)
855853

856-
return sellers
857-
858854

859855
@router.patch(
860856
"/myeclpay/stores/{store_id}/sellers/{seller_user_id}",
@@ -1190,13 +1186,11 @@ async def get_user_devices(
11901186
detail="User is not registered for MyECL Pay",
11911187
)
11921188

1193-
wallet_devices = await cruds_myeclpay.get_wallet_devices_by_wallet_id(
1189+
return await cruds_myeclpay.get_wallet_devices_by_wallet_id(
11941190
wallet_id=user_payment.wallet_id,
11951191
db=db,
11961192
)
11971193

1198-
return wallet_devices
1199-
12001194

12011195
@router.get(
12021196
"/myeclpay/users/me/wallet/devices/{wallet_device_id}",
@@ -1707,7 +1701,7 @@ async def add_transfer_by_admin(
17071701

17081702
message = Message(
17091703
title="💳 Paiement - transfert",
1710-
content=f"Votre compte a été crédité de {transfer_info.amount/100} €",
1704+
content=f"Votre compte a été crédité de {transfer_info.amount / 100} €",
17111705
action_module="MyECLPay",
17121706
)
17131707
await notification_tool.send_notification_to_user(
@@ -2189,7 +2183,7 @@ async def store_scan_qrcode(
21892183

21902184
message = Message(
21912185
title=f"💳 Paiement - {store.name}",
2192-
content=f"Une transaction de {scan_info.tot/100} € a été effectuée",
2186+
content=f"Une transaction de {scan_info.tot / 100} € a été effectuée",
21932187
action_module="MyECLPay",
21942188
)
21952189
await notification_tool.send_notification_to_user(
@@ -2364,7 +2358,7 @@ async def refund_transaction(
23642358
if wallet_previously_debited.user is not None:
23652359
message = Message(
23662360
title="💳 Remboursement",
2367-
content=f"La transaction pour {wallet_previously_credited_name} ({transaction.total/100} €) a été remboursée de {refund_amount/100} €",
2361+
content=f"La transaction pour {wallet_previously_credited_name} ({transaction.total / 100} €) a été remboursée de {refund_amount / 100} €",
23682362
action_module="MyECLPay",
23692363
)
23702364
await notification_tool.send_notification_to_user(
@@ -2379,7 +2373,7 @@ async def refund_transaction(
23792373
wallet_previously_debited_name = wallet_previously_debited.store.name
23802374
message = Message(
23812375
title="💳 Remboursement",
2382-
content=f"Vous avez remboursé la transaction de {wallet_previously_debited_name} ({transaction.total/100} €) de {refund_amount/100} €",
2376+
content=f"Vous avez remboursé la transaction de {wallet_previously_debited_name} ({transaction.total / 100} €) de {refund_amount / 100} €",
23832377
action_module="MyECLPay",
23842378
)
23852379
await notification_tool.send_notification_to_user(
@@ -2510,7 +2504,7 @@ async def cancel_transaction(
25102504
if debited_wallet.user is not None:
25112505
message = Message(
25122506
title="💳 Paiement annulé",
2513-
content=f"La transaction de {transaction.total/100} € a été annulée",
2507+
content=f"La transaction de {transaction.total / 100} € a été annulée",
25142508
action_module="MyECLPay",
25152509
)
25162510
await notification_tool.send_notification_to_user(

app/core/notification/notification_types.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ def __init__(self, topic: Topic, topic_identifier: str = ""):
2626
def to_str(self) -> str:
2727
if self.topic_identifier:
2828
return f"{self.topic.value}_{self.topic_identifier}"
29-
else:
30-
return self.topic.value
29+
return self.topic.value
3130

3231
@classmethod
3332
def from_str(cls, topic_str: str):

app/core/payment/schemas_payment.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class CheckoutComplete(BaseModel):
2424

2525
payments: list[CheckoutPayment]
2626

27-
@computed_field # type: ignore
27+
@computed_field # type: ignore[misc] # Current issue with mypy, see https://docs.pydantic.dev/2.0/usage/computed_fields/ and https://github.com/python/mypy/issues/1362
2828
@property
2929
def payment_completed(self) -> bool:
3030
total_paid = sum([payment.paid_amount for payment in self.payments])

0 commit comments

Comments
 (0)