chore: update .gitignore and enhance docstrings across multiple files

- Added *.pyc and *.pyo to .gitignore to prevent compiled Python files from being tracked.
- Improved docstrings in various modules, providing clearer descriptions of functions, parameters, and return values to enhance code readability and maintainability.
This commit is contained in:
zhangtao
2026-04-04 01:21:59 +08:00
parent dcf8844453
commit b0ae6af3b1
96 changed files with 5089 additions and 304 deletions
+15 -9
View File
@@ -9,12 +9,15 @@ from app.core.exceptions import CustomException
def http_limit_callback(request: Request, response: Response, expire: int) -> NoReturn:
"""
请求限制时的默认回调函数
HTTP 触发限流时的默认回调:抛出 429。
:param request: FastAPI 请求对象
:param response: FastAPI 响应对象
:param expire: 剩余毫秒数
:return:
参数:
- request (Request): 当前请求。
- response (Response): 当前响应(未直接使用,保留与限流器签名一致)。
- expire (int): 剩余冷却毫秒数。
返回:
- 无(始终抛出 CustomException)。
"""
expires = ceil(expire / 30)
raise CustomException(
@@ -26,11 +29,14 @@ def http_limit_callback(request: Request, response: Response, expire: int) -> No
async def ws_limit_callback(ws: WebSocket, expire: int) -> None:
"""
WebSocket请求限制时的默认回调函数
WebSocket 触发限流时的默认回调:关闭连接。
:param ws: WebSocket连接对象
:param expire: 剩余毫秒数
:return:
参数:
- ws (WebSocket): 当前 WebSocket。
- expire (int): 剩余冷却毫秒数。
返回:
- None
"""
expires = ceil(expire / 30)
await ws.close(code=1008, reason=f"请求过于频繁,请稍后重试!{expires} 秒后重试")