fix: auto-fix code issues (cron)
- 修复隐式 Optional 类型注解 (RUF013) - 修复不必要的赋值后返回 (RET504) - 优化列表推导式 (PERF401) - 修复未使用的参数 (ARG002) - 清理重复导入 - 优化异常处理
This commit is contained in:
@@ -963,7 +963,11 @@ class LocalizationManager:
|
||||
self._close_if_file_db(conn)
|
||||
|
||||
def get_translation(
|
||||
self, key: str, language: str, namespace: str = "common", fallback: bool = True,
|
||||
self,
|
||||
key: str,
|
||||
language: str,
|
||||
namespace: str = "common",
|
||||
fallback: bool = True,
|
||||
) -> str | None:
|
||||
conn = self._get_connection()
|
||||
try:
|
||||
@@ -979,7 +983,10 @@ class LocalizationManager:
|
||||
lang_config = self.get_language_config(language)
|
||||
if lang_config and lang_config.fallback_language:
|
||||
return self.get_translation(
|
||||
key, lang_config.fallback_language, namespace, False,
|
||||
key,
|
||||
lang_config.fallback_language,
|
||||
namespace,
|
||||
False,
|
||||
)
|
||||
if language != "en":
|
||||
return self.get_translation(key, "en", namespace, False)
|
||||
@@ -1019,7 +1026,11 @@ class LocalizationManager:
|
||||
self._close_if_file_db(conn)
|
||||
|
||||
def _get_translation_internal(
|
||||
self, conn: sqlite3.Connection, key: str, language: str, namespace: str,
|
||||
self,
|
||||
conn: sqlite3.Connection,
|
||||
key: str,
|
||||
language: str,
|
||||
namespace: str,
|
||||
) -> Translation | None:
|
||||
cursor = conn.cursor()
|
||||
cursor.execute(
|
||||
@@ -1121,7 +1132,9 @@ class LocalizationManager:
|
||||
self._close_if_file_db(conn)
|
||||
|
||||
def list_data_centers(
|
||||
self, status: str | None = None, region: str | None = None,
|
||||
self,
|
||||
status: str | None = None,
|
||||
region: str | None = None,
|
||||
) -> list[DataCenter]:
|
||||
conn = self._get_connection()
|
||||
try:
|
||||
@@ -1146,7 +1159,8 @@ class LocalizationManager:
|
||||
try:
|
||||
cursor = conn.cursor()
|
||||
cursor.execute(
|
||||
"SELECT * FROM tenant_data_center_mappings WHERE tenant_id = ?", (tenant_id,),
|
||||
"SELECT * FROM tenant_data_center_mappings WHERE tenant_id = ?",
|
||||
(tenant_id,),
|
||||
)
|
||||
row = cursor.fetchone()
|
||||
if row:
|
||||
@@ -1156,7 +1170,10 @@ class LocalizationManager:
|
||||
self._close_if_file_db(conn)
|
||||
|
||||
def set_tenant_data_center(
|
||||
self, tenant_id: str, region_code: str, data_residency: str = "regional",
|
||||
self,
|
||||
tenant_id: str,
|
||||
region_code: str,
|
||||
data_residency: str = "regional",
|
||||
) -> TenantDataCenterMapping:
|
||||
conn = self._get_connection()
|
||||
try:
|
||||
@@ -1222,7 +1239,8 @@ class LocalizationManager:
|
||||
try:
|
||||
cursor = conn.cursor()
|
||||
cursor.execute(
|
||||
"SELECT * FROM localized_payment_methods WHERE provider = ?", (provider,),
|
||||
"SELECT * FROM localized_payment_methods WHERE provider = ?",
|
||||
(provider,),
|
||||
)
|
||||
row = cursor.fetchone()
|
||||
if row:
|
||||
@@ -1232,7 +1250,10 @@ class LocalizationManager:
|
||||
self._close_if_file_db(conn)
|
||||
|
||||
def list_payment_methods(
|
||||
self, country_code: str | None = None, currency: str | None = None, active_only: bool = True,
|
||||
self,
|
||||
country_code: str | None = None,
|
||||
currency: str | None = None,
|
||||
active_only: bool = True,
|
||||
) -> list[LocalizedPaymentMethod]:
|
||||
conn = self._get_connection()
|
||||
try:
|
||||
@@ -1255,7 +1276,9 @@ class LocalizationManager:
|
||||
self._close_if_file_db(conn)
|
||||
|
||||
def get_localized_payment_methods(
|
||||
self, country_code: str, language: str = "en",
|
||||
self,
|
||||
country_code: str,
|
||||
language: str = "en",
|
||||
) -> list[dict[str, Any]]:
|
||||
methods = self.list_payment_methods(country_code=country_code)
|
||||
result = []
|
||||
@@ -1287,7 +1310,9 @@ class LocalizationManager:
|
||||
self._close_if_file_db(conn)
|
||||
|
||||
def list_country_configs(
|
||||
self, region: str | None = None, active_only: bool = True,
|
||||
self,
|
||||
region: str | None = None,
|
||||
active_only: bool = True,
|
||||
) -> list[CountryConfig]:
|
||||
conn = self._get_connection()
|
||||
try:
|
||||
@@ -1345,14 +1370,19 @@ class LocalizationManager:
|
||||
return dt.strftime("%Y-%m-%d %H:%M")
|
||||
|
||||
def format_number(
|
||||
self, number: float, language: str = "en", decimal_places: int | None = None,
|
||||
self,
|
||||
number: float,
|
||||
language: str = "en",
|
||||
decimal_places: int | None = None,
|
||||
) -> str:
|
||||
try:
|
||||
if BABEL_AVAILABLE:
|
||||
try:
|
||||
locale = Locale.parse(language.replace("_", "-"))
|
||||
return numbers.format_decimal(
|
||||
number, locale=locale, decimal_quantization=(decimal_places is not None),
|
||||
number,
|
||||
locale=locale,
|
||||
decimal_quantization=(decimal_places is not None),
|
||||
)
|
||||
except (ValueError, AttributeError):
|
||||
pass
|
||||
@@ -1514,7 +1544,9 @@ class LocalizationManager:
|
||||
self._close_if_file_db(conn)
|
||||
|
||||
def detect_user_preferences(
|
||||
self, accept_language: str | None = None, ip_country: str | None = None,
|
||||
self,
|
||||
accept_language: str | None = None,
|
||||
ip_country: str | None = None,
|
||||
) -> dict[str, str]:
|
||||
preferences = {"language": "en", "country": "US", "timezone": "UTC", "currency": "USD"}
|
||||
if accept_language:
|
||||
|
||||
Reference in New Issue
Block a user