fix: auto-fix code issues (cron)

- 修复隐式 Optional 类型注解 (RUF013)
- 修复不必要的赋值后返回 (RET504)
- 优化列表推导式 (PERF401)
- 修复未使用的参数 (ARG002)
- 清理重复导入
- 优化异常处理
This commit is contained in:
AutoFix Bot
2026-03-03 21:11:47 +08:00
parent d17a58ceae
commit 259f2c90d0
36 changed files with 1651 additions and 863 deletions

View File

@@ -433,7 +433,8 @@ class TenantManager:
TenantTier(tier) if tier in [t.value for t in TenantTier] else TenantTier.FREE
)
resource_limits = self.DEFAULT_LIMITS.get(
tier_enum, self.DEFAULT_LIMITS[TenantTier.FREE],
tier_enum,
self.DEFAULT_LIMITS[TenantTier.FREE],
)
tenant = Tenant(
@@ -612,7 +613,11 @@ class TenantManager:
conn.close()
def list_tenants(
self, status: str | None = None, tier: str | None = None, limit: int = 100, offset: int = 0,
self,
status: str | None = None,
tier: str | None = None,
limit: int = 100,
offset: int = 0,
) -> list[Tenant]:
"""列出租户"""
conn = self._get_connection()
@@ -1103,7 +1108,11 @@ class TenantManager:
conn.close()
def update_member_role(
self, tenant_id: str, member_id: str, role: str, permissions: list[str] | None = None,
self,
tenant_id: str,
member_id: str,
role: str,
permissions: list[str] | None = None,
) -> bool:
"""更新成员角色"""
conn = self._get_connection()
@@ -1268,7 +1277,10 @@ class TenantManager:
conn.close()
def get_usage_stats(
self, tenant_id: str, start_date: datetime | None = None, end_date: datetime | None = None,
self,
tenant_id: str,
start_date: datetime | None = None,
end_date: datetime | None = None,
) -> dict[str, Any]:
"""获取使用统计"""
conn = self._get_connection()
@@ -1314,23 +1326,28 @@ class TenantManager:
"limits": limits,
"usage_percentages": {
"storage": self._calc_percentage(
row["total_storage"] or 0, limits.get("max_storage_mb", 0) * 1024 * 1024,
row["total_storage"] or 0,
limits.get("max_storage_mb", 0) * 1024 * 1024,
),
"transcription": self._calc_percentage(
row["total_transcription"] or 0,
limits.get("max_transcription_minutes", 0) * 60,
),
"api_calls": self._calc_percentage(
row["total_api_calls"] or 0, limits.get("max_api_calls_per_day", 0),
row["total_api_calls"] or 0,
limits.get("max_api_calls_per_day", 0),
),
"projects": self._calc_percentage(
row["max_projects"] or 0, limits.get("max_projects", 0),
row["max_projects"] or 0,
limits.get("max_projects", 0),
),
"entities": self._calc_percentage(
row["max_entities"] or 0, limits.get("max_entities", 0),
row["max_entities"] or 0,
limits.get("max_entities", 0),
),
"members": self._calc_percentage(
row["max_members"] or 0, limits.get("max_team_members", 0),
row["max_members"] or 0,
limits.get("max_team_members", 0),
),
},
}
@@ -1406,8 +1423,10 @@ class TenantManager:
def _validate_domain(self, domain: str) -> bool:
"""验证域名格式"""
pattern = (r"^(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]{0, 61}[a-zA-Z0-9])?\.)*"
r"[a-zA-Z0-9](?:[a-zA-Z0-9-]{0, 61}[a-zA-Z0-9])$")
pattern = (
r"^(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]{0, 61}[a-zA-Z0-9])?\.)*"
r"[a-zA-Z0-9](?:[a-zA-Z0-9-]{0, 61}[a-zA-Z0-9])$"
)
return bool(re.match(pattern, domain))
def _check_domain_verification(self, domain: str, token: str, method: str) -> bool: