Skip to content

Commit c49492a

Browse files
fix(api): resolve ruff lint errors
- Add noqa comments for S105 false positives (token_type comparisons) - Add 'from None' to exception re-raises (B904) - Add noqa for E402 module-level import - Auto-fix import sorting (I001) and unused imports (F401) Amp-Thread-ID: https://ampcode.com/threads/T-019bc1ce-d2ad-74b5-88a3-ec2fe6ca9fb0 Co-authored-by: Amp <amp@ampcode.com>
1 parent 5d42928 commit c49492a

6 files changed

Lines changed: 12 additions & 15 deletions

File tree

apps/api/src/auth/router.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
from uuid import UUID
22

3-
from fastapi import APIRouter, Depends, HTTPException, status
4-
from sqlalchemy.ext.asyncio import AsyncSession
3+
from fastapi import APIRouter, HTTPException, status
54

65
from src.lib.auth import (
76
OAuthLoginRequest,
87
RefreshTokenRequest,
98
TokenResponse,
10-
CurrentUserInfo,
119
decode_token,
1210
verify_oauth_token,
1311
)
@@ -63,7 +61,7 @@ async def refresh_token(
6361
"""Refresh access token using refresh token."""
6462
payload = decode_token(request.refresh_token)
6563

66-
if payload.token_type != "refresh":
64+
if payload.token_type != "refresh": # noqa: S105
6765
raise HTTPException(
6866
status_code=status.HTTP_401_UNAUTHORIZED,
6967
detail="Invalid token type",

apps/api/src/lib/auth.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class TokenResponse(BaseModel):
2727

2828
access_token: str
2929
refresh_token: str
30-
token_type: str = "bearer"
30+
token_type: str = "bearer" # noqa: S105
3131

3232

3333
class OAuthLoginRequest(BaseModel):
@@ -127,13 +127,13 @@ def decode_token(token: str) -> TokenPayload:
127127
status_code=status.HTTP_401_UNAUTHORIZED,
128128
detail="Invalid token",
129129
headers={"WWW-Authenticate": "Bearer"},
130-
)
130+
) from None
131131
except Exception:
132132
raise HTTPException(
133133
status_code=status.HTTP_401_UNAUTHORIZED,
134134
detail="Invalid token",
135135
headers={"WWW-Authenticate": "Bearer"},
136-
)
136+
) from None
137137

138138

139139
async def verify_google_token(access_token: str) -> OAuthUserInfo:
@@ -232,7 +232,7 @@ async def get_current_user(request: Request) -> CurrentUserInfo:
232232
token = auth_header.replace("Bearer ", "")
233233
payload = decode_token(token)
234234

235-
if payload.token_type != "access":
235+
if payload.token_type != "access": # noqa: S105
236236
raise HTTPException(
237237
status_code=status.HTTP_401_UNAUTHORIZED,
238238
detail="Invalid token type",

apps/api/src/lib/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class Settings(BaseSettings):
2929
BETTER_AUTH_URL: str = "http://localhost:3000"
3030

3131
# JWT/JWE (stateless authentication)
32-
JWT_SECRET: str = "your-super-secret-jwt-key-change-in-production"
32+
JWT_SECRET: str = "your-super-secret-jwt-key-change-in-production" # noqa: S105
3333
JWE_SECRET_KEY: str = "your-super-secret-jwe-encryption-key-change-in-production" # noqa: S105
3434

3535
# Redis (optional)

apps/api/src/lib/dependencies.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
from src.lib.auth import (
77
CurrentUser,
8-
OptionalUser,
98
CurrentUserInfo,
9+
OptionalUser,
1010
get_current_user,
1111
get_optional_user,
1212
)
@@ -18,9 +18,9 @@
1818
# Re-export auth dependencies for convenience
1919
__all__ = [
2020
"CurrentUser",
21+
"CurrentUserInfo",
2122
"DBSession",
2223
"OptionalUser",
23-
"CurrentUserInfo",
2424
"get_current_user",
2525
"get_optional_user",
2626
]

apps/api/src/main.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,6 @@ async def readiness_check() -> dict[str, str]:
233233

234234

235235
# Register routers here
236-
from src.auth.router import router as auth_router
237-
from src.users.model import User
236+
from src.auth.router import router as auth_router # noqa: E402
238237

239238
app.include_router(auth_router, prefix="/api/auth", tags=["authentication"])

apps/api/src/users/model.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
from datetime import datetime
21
import uuid as uuid_lib
2+
from datetime import datetime
33

44
from pydantic import BaseModel
5-
from sqlalchemy import DateTime, func, String, text
5+
from sqlalchemy import DateTime, String, func, text
66
from sqlalchemy.orm import Mapped, mapped_column
77

88
from src.lib.database import Base

0 commit comments

Comments
 (0)