执行 Ruff 安全自动修复

This commit is contained in:
yml2213
2026-08-31 10:28:14 +08:00
parent 2a1d27f953
commit b58c6b4357
145 changed files with 940 additions and 993 deletions
+7 -6
View File
@@ -6,9 +6,10 @@ import hashlib
import json
import os
import time
from collections.abc import Callable, Mapping
from dataclasses import dataclass
from decimal import Decimal, InvalidOperation
from typing import Any, Callable, Mapping
from typing import Any
import requests
@@ -34,7 +35,7 @@ class FishFinRechargeConfig:
debug: bool = False
@classmethod
def from_env(cls) -> "FishFinRechargeConfig":
def from_env(cls) -> FishFinRechargeConfig:
"""从环境变量读取配置,不在代码或数据库中保存商户密钥。"""
timeout = float(os.getenv("FISH_FIN_RECHARGE_TIMEOUT", "20"))
return cls(
@@ -189,7 +190,7 @@ class FishFinRechargeClient:
"sign_params": sign_params,
# 不把可重放签名原文或 AppSecret 写入日志,只记录待签名串摘要。
"sign_source_digest": hashlib.sha256(
f"{sign_query}{method.upper()}".encode("utf-8")
f"{sign_query}{method.upper()}".encode()
).hexdigest()[:12],
}
)
@@ -240,7 +241,7 @@ class FishFinRechargeClient:
return payload
@staticmethod
def _amount(value: Decimal | int | float | str) -> str:
def _amount(value: Decimal | float | str) -> str:
"""规范化金额,避免浮点数表达式进入签名或订单请求。"""
try:
price = Decimal(str(value))
@@ -251,7 +252,7 @@ class FishFinRechargeClient:
return format(price.normalize(), "f")
@classmethod
def _json_amount(cls, value: Decimal | int | float | str) -> int | float:
def _json_amount(cls, value: Decimal | float | str) -> int | float:
"""按文档以 JSON 数字发送金额,整数不附带无意义的小数位。"""
amount_text = cls._amount(value)
return int(amount_text) if "." not in amount_text else float(amount_text)
@@ -267,7 +268,7 @@ class FishFinRechargeClient:
self,
*,
buy_num: int,
pay_amount: Decimal | int | float | str,
pay_amount: Decimal | float | str,
out_order_id: str,
product_id: str,
recharge_arg: list[dict[str, Any]],