fix: restore multi-exception syntax

This commit is contained in:
jxxghp
2026-09-02 20:22:57 +08:00
parent e5f6aaad48
commit c20515971a
23 changed files with 47 additions and 47 deletions
+3 -3
View File
@@ -267,7 +267,7 @@ class StreamingHandler:
try: try:
channel_enum = NotificationChannel(self._channel) channel_enum = NotificationChannel(self._channel)
self._max_message_length = ChannelCapabilityManager.get_max_message_length(channel_enum) self._max_message_length = ChannelCapabilityManager.get_max_message_length(channel_enum)
except ValueError, KeyError: except (ValueError, KeyError):
self._max_message_length = 0 self._max_message_length = 0
# 启动异步定时刷新任务 # 启动异步定时刷新任务
@@ -567,7 +567,7 @@ class StreamingHandler:
try: try:
channel_enum = NotificationChannel(self._channel) channel_enum = NotificationChannel(self._channel)
return ChannelCapabilityManager.supports_capability(channel_enum, ChannelCapability.MESSAGE_EDITING) return ChannelCapabilityManager.supports_capability(channel_enum, ChannelCapability.MESSAGE_EDITING)
except ValueError, KeyError: except (ValueError, KeyError):
return False return False
def _get_rich_message(self, text: str) -> Optional[str]: def _get_rich_message(self, text: str) -> Optional[str]:
@@ -707,7 +707,7 @@ class StreamingHandler:
# 后续更新:编辑已有消息 # 后续更新:编辑已有消息
try: try:
channel_enum = NotificationChannel(self._channel) channel_enum = NotificationChannel(self._channel)
except ValueError, KeyError: except (ValueError, KeyError):
return return
metadata = dict(self._message_response.metadata or {}) metadata = dict(self._message_response.metadata or {})
+1 -1
View File
@@ -179,7 +179,7 @@ def _extract_version(skill_md: Path) -> int:
return 0 return 0
try: try:
return int(raw) return int(raw)
except ValueError, TypeError: except (ValueError, TypeError):
return 0 return 0
+5 -5
View File
@@ -489,7 +489,7 @@ class MoviePilotAgent:
content = re.sub(r"\s*```$", "", content).strip() content = re.sub(r"\s*```$", "", content).strip()
try: try:
payload = json.loads(content) payload = json.loads(content)
except TypeError, ValueError: except (TypeError, ValueError):
return "" return ""
if not isinstance(payload, dict): if not isinstance(payload, dict):
return "" return ""
@@ -561,7 +561,7 @@ class MoviePilotAgent:
return None return None
try: try:
return int(value) return int(value)
except TypeError, ValueError: except (TypeError, ValueError):
return None return None
@staticmethod @staticmethod
@@ -576,7 +576,7 @@ class MoviePilotAgent:
"""读取 LangGraph 递归上限,防止模型持续循环调用工具。""" """读取 LangGraph 递归上限,防止模型持续循环调用工具。"""
try: try:
limit = int(get_runtime_setting("LLM_MAX_ITERATIONS") or 0) limit = int(get_runtime_setting("LLM_MAX_ITERATIONS") or 0)
except TypeError, ValueError: except (TypeError, ValueError):
limit = 0 limit = 0
return limit if limit > 0 else 128 return limit if limit > 0 else 128
@@ -1167,7 +1167,7 @@ class MoviePilotAgent:
try: try:
channel_enum = NotificationChannel(self.channel) channel_enum = NotificationChannel(self.channel)
return ChannelCapabilityManager.supports_capability(channel_enum, ChannelCapability.MESSAGE_EDITING) return ChannelCapabilityManager.supports_capability(channel_enum, ChannelCapability.MESSAGE_EDITING)
except ValueError, KeyError: except (ValueError, KeyError):
return False return False
@staticmethod @staticmethod
@@ -1340,7 +1340,7 @@ class MoviePilotAgent:
if body is not None: if body is not None:
try: try:
parts.append(json.dumps(body, ensure_ascii=False)) parts.append(json.dumps(body, ensure_ascii=False))
except TypeError, ValueError: except (TypeError, ValueError):
parts.append(str(body)) parts.append(str(body))
return " ".join(part for part in parts if part) return " ".join(part for part in parts if part)
+1 -1
View File
@@ -60,7 +60,7 @@ def _normalize_policy_arguments(tool: Any, arguments: Mapping[str, Any]) -> dict
try: try:
validated = args_schema.model_validate(raw_arguments) validated = args_schema.model_validate(raw_arguments)
return validated.model_dump(mode="json") return validated.model_dump(mode="json")
except AttributeError, TypeError, ValueError, ValidationError: except (AttributeError, TypeError, ValueError, ValidationError):
# 实际 handler 仍负责既有参数错误语义;策略观测按原始值保守处理。 # 实际 handler 仍负责既有参数错误语义;策略观测按原始值保守处理。
return raw_arguments return raw_arguments
+2 -2
View File
@@ -528,7 +528,7 @@ def _redact_basic_auth(
padded_token = token + "=" * (-len(token) % 4) padded_token = token + "=" * (-len(token) % 4)
try: try:
decoded = base64.b64decode(padded_token, validate=True) decoded = base64.b64decode(padded_token, validate=True)
except binascii.Error, ValueError: except (binascii.Error, ValueError):
return match.group(0) return match.group(0)
if b":" not in decoded: if b":" not in decoded:
return match.group(0) return match.group(0)
@@ -730,7 +730,7 @@ def sanitize_for_host(
if not truncated and value.strip().startswith(("{", "[")): if not truncated and value.strip().startswith(("{", "[")):
try: try:
parsed = json.loads(value) parsed = json.loads(value)
except TypeError, ValueError, json.JSONDecodeError: except (TypeError, ValueError, json.JSONDecodeError):
pass pass
else: else:
sanitized_json = sanitize_for_host( sanitized_json = sanitize_for_host(
+1 -1
View File
@@ -821,7 +821,7 @@ class AgentRuntimeManager:
return default return default
try: try:
return int(value) return int(value)
except TypeError, ValueError: except (TypeError, ValueError):
return default return default
def _validate_runtime_config( def _validate_runtime_config(
+1 -1
View File
@@ -113,7 +113,7 @@ def parse_skill_metadata( # noqa: C901
if raw_version is not None: if raw_version is not None:
try: try:
version = int(raw_version) version = int(raw_version)
except ValueError, TypeError: except (ValueError, TypeError):
logger.warning( logger.warning(
"Invalid 'version' in %s (got %r), defaulting to 0", "Invalid 'version' in %s (got %r), defaulting to 0",
skill_path, skill_path,
+2 -2
View File
@@ -292,13 +292,13 @@ class MoviePilotToolsManager:
if field_type == "integer" and isinstance(value, str): if field_type == "integer" and isinstance(value, str):
try: try:
return int(value) return int(value)
except ValueError, TypeError: except (ValueError, TypeError):
logger.warning(f"无法将参数 {key}='{value}' 转换为整数,返回 None") logger.warning(f"无法将参数 {key}='{value}' 转换为整数,返回 None")
return None return None
if field_type == "number" and isinstance(value, str): if field_type == "number" and isinstance(value, str):
try: try:
return float(value) return float(value)
except ValueError, TypeError: except (ValueError, TypeError):
logger.warning(f"无法将参数 {key}='{value}' 转换为浮点数,返回 None") logger.warning(f"无法将参数 {key}='{value}' 转换为浮点数,返回 None")
return None return None
if field_type == "boolean": if field_type == "boolean":
+1 -1
View File
@@ -101,7 +101,7 @@ def _build_unrecognized_media_info(
) )
try: try:
media_type = MediaType(torrent.category) media_type = MediaType(torrent.category)
except TypeError, ValueError: except (TypeError, ValueError):
media_type = MediaType.from_agent(torrent.category) media_type = MediaType.from_agent(torrent.category)
if media_type == MediaType.COLLECTION: if media_type == MediaType.COLLECTION:
media_type = MediaType.MOVIE media_type = MediaType.MOVIE
+1 -1
View File
@@ -1254,7 +1254,7 @@ async def terminate_web_agent_audio_process(
return return
try: try:
await process.communicate() await process.communicate()
except OSError, ProcessLookupError: except (OSError, ProcessLookupError):
pass pass
+9 -9
View File
@@ -32,7 +32,7 @@ def normalize_episode_priority(
for episode, priority in episode_priority.items(): for episode, priority in episode_priority.items():
try: try:
normalized[str(int(episode))] = int(priority) normalized[str(int(episode))] = int(priority)
except TypeError, ValueError: except (TypeError, ValueError):
continue continue
return normalized return normalized
@@ -98,7 +98,7 @@ def get_downloaded_best_version_episodes(
for episode in subscribe.note or []: for episode in subscribe.note or []:
try: try:
episode_number = int(episode) episode_number = int(episode)
except TypeError, ValueError: except (TypeError, ValueError):
continue continue
if episode_number in target_episodes: if episode_number in target_episodes:
downloaded.add(episode_number) downloaded.add(episode_number)
@@ -110,7 +110,7 @@ def get_downloaded_best_version_episodes(
episode_number = int(episode_key) episode_number = int(episode_key)
if episode_number in target_episodes: if episode_number in target_episodes:
downloaded.add(episode_number) downloaded.add(episode_number)
except TypeError, ValueError: except (TypeError, ValueError):
continue continue
return sorted(downloaded) return sorted(downloaded)
@@ -191,7 +191,7 @@ def compute_lack_episode(
for episode in subscribe.note or []: for episode in subscribe.note or []:
try: try:
episode_number = int(episode) episode_number = int(episode)
except TypeError, ValueError: except (TypeError, ValueError):
continue continue
if episode_number in target_episodes: if episode_number in target_episodes:
downloaded.add(episode_number) downloaded.add(episode_number)
@@ -200,7 +200,7 @@ def compute_lack_episode(
if float(priority) <= 0: if float(priority) <= 0:
continue continue
episode_number = int(episode_key) episode_number = int(episode_key)
except TypeError, ValueError: except (TypeError, ValueError):
continue continue
if episode_number in target_episodes: if episode_number in target_episodes:
downloaded.add(episode_number) downloaded.add(episode_number)
@@ -429,7 +429,7 @@ def get_downloaded_episodes(downloads: Optional[List[Context]]) -> List[int]:
for episode in selected_episodes or []: for episode in selected_episodes or []:
try: try:
downloaded_episodes.add(int(episode)) downloaded_episodes.add(int(episode))
except TypeError, ValueError: except (TypeError, ValueError):
continue continue
return sorted(downloaded_episodes) return sorted(downloaded_episodes)
@@ -480,7 +480,7 @@ def get_best_version_interested_episodes(
for episode in selected_episodes: for episode in selected_episodes:
try: try:
episode_num = int(episode) episode_num = int(episode)
except TypeError, ValueError: except (TypeError, ValueError):
continue continue
if episode_num not in target_episodes: if episode_num not in target_episodes:
continue continue
@@ -503,7 +503,7 @@ def prepare_best_version_tv_candidate(
if is_full_best_version_enabled(subscribe): if is_full_best_version_enabled(subscribe):
try: try:
return int(priority or 0) > int(subscribe.current_priority or 0) return int(priority or 0) > int(subscribe.current_priority or 0)
except TypeError, ValueError: except (TypeError, ValueError):
return False return False
interested_episodes = get_best_version_interested_episodes( interested_episodes = get_best_version_interested_episodes(
@@ -566,7 +566,7 @@ def should_prefer_full_pack_for_episode_best_version(
try: try:
resource_priority = int(priority or 0) resource_priority = int(priority or 0)
except TypeError, ValueError: except (TypeError, ValueError):
resource_priority = 0 resource_priority = 0
episode_priority = get_episode_priority(subscribe) episode_priority = get_episode_priority(subscribe)
+2 -2
View File
@@ -394,7 +394,7 @@ class SystemService:
if cron: if cron:
try: try:
TimerUtils.normalize_schedule_trigger("cron", cron, self.settings.get("TZ")) TimerUtils.normalize_schedule_trigger("cron", cron, self.settings.get("TZ"))
except TypeError, ValueError: except (TypeError, ValueError):
return "数据库备份周期格式不正确" return "数据库备份周期格式不正确"
backup_path = env.get("DB_BACKUP_PATH", self.settings.get("DB_BACKUP_PATH")) backup_path = env.get("DB_BACKUP_PATH", self.settings.get("DB_BACKUP_PATH"))
if backup_path is not None and not isinstance(backup_path, str): if backup_path is not None and not isinstance(backup_path, str):
@@ -408,7 +408,7 @@ class SystemService:
return f"{label}必须是大于等于 0 的整数" return f"{label}必须是大于等于 0 的整数"
try: try:
converted = int(value) converted = int(value)
except TypeError, ValueError: except (TypeError, ValueError):
return f"{label}必须是大于等于 0 的整数" return f"{label}必须是大于等于 0 的整数"
if converted < 0 or str(value).strip() != str(converted): if converted < 0 or str(value).strip() != str(converted):
return f"{label}必须是大于等于 0 的整数" return f"{label}必须是大于等于 0 的整数"
+3 -3
View File
@@ -78,7 +78,7 @@ class SearchPaginationOwner(_SearchOwnerBase):
pages = get_chain_runtime_config_snapshot().search_resource_pages pages = get_chain_runtime_config_snapshot().search_resource_pages
try: try:
pages = int(pages) pages = int(pages)
except TypeError, ValueError: except (TypeError, ValueError):
return 1 return 1
return max(pages, 1) return max(pages, 1)
@@ -89,7 +89,7 @@ class SearchPaginationOwner(_SearchOwnerBase):
""" """
try: try:
start_page = int(page or 0) start_page = int(page or 0)
except TypeError, ValueError: except (TypeError, ValueError):
start_page = 0 start_page = 0
start_page = max(start_page, 0) start_page = max(start_page, 0)
return list(range(start_page, start_page + cls._get_search_resource_pages())) return list(range(start_page, start_page + cls._get_search_resource_pages()))
@@ -114,7 +114,7 @@ class SearchPaginationOwner(_SearchOwnerBase):
subtitle_conf = (site or {}).get("subtitles") or {} subtitle_conf = (site or {}).get("subtitles") or {}
try: try:
page_size = int(subtitle_conf.get("result_num") or site.get("result_num") or 100) page_size = int(subtitle_conf.get("result_num") or site.get("result_num") or 100)
except TypeError, ValueError: except (TypeError, ValueError):
page_size = 100 page_size = 100
return page_size > 0 and len(page_results or []) >= page_size return page_size > 0 and len(page_results or []) >= page_size
+1 -1
View File
@@ -38,7 +38,7 @@ def _site_request_interval(site: SiteIndexer) -> float:
"""读取站点管理中已有的单次访问间隔配置。""" """读取站点管理中已有的单次访问间隔配置。"""
try: try:
return max(0.0, float(site.get("limit_seconds") or 0)) return max(0.0, float(site.get("limit_seconds") or 0))
except TypeError, ValueError: except (TypeError, ValueError):
return 0.0 return 0.0
+1 -1
View File
@@ -246,7 +246,7 @@ class SearchRecommendOwner(_SearchOwnerBase):
for index in ai_indices: for index in ai_indices:
try: try:
value = int(index) value = int(index)
except TypeError, ValueError: except (TypeError, ValueError):
continue continue
if value in seen: if value in seen:
continue continue
+1 -1
View File
@@ -346,7 +346,7 @@ class SubscribeCompletionOwner(_SubscribeOwnerBase):
for episode in episodes: for episode in episodes:
try: try:
episode_number = int(episode) episode_number = int(episode)
except TypeError, ValueError: except (TypeError, ValueError):
continue continue
if episode_number not in self._SubscribeChain__get_best_version_target_episodes(subscribe): if episode_number not in self._SubscribeChain__get_best_version_target_episodes(subscribe):
continue continue
+1 -1
View File
@@ -657,7 +657,7 @@ class SubscribeRefreshOwner(SubscribeMetadataOwner):
for episode in episodes or []: for episode in episodes or []:
try: try:
episode_number = int(episode) episode_number = int(episode)
except TypeError, ValueError: except (TypeError, ValueError):
ignored.append({"episode": episode, "reason": "invalid"}) ignored.append({"episode": episode, "reason": "invalid"})
continue continue
if episode_number not in target_episodes: if episode_number not in target_episodes:
+5 -5
View File
@@ -61,7 +61,7 @@ def _read_json_file(path: Path) -> Optional[Dict[str, Any]]:
return None return None
try: try:
return json.loads(path.read_text(encoding="utf-8", errors="replace")) return json.loads(path.read_text(encoding="utf-8", errors="replace"))
except OSError, json.JSONDecodeError: except (OSError, json.JSONDecodeError):
return None return None
@@ -84,7 +84,7 @@ def _get_process(runtime: Optional[Dict[str, Any]] = None) -> Optional[psutil.Pr
try: try:
process = psutil.Process(int(pid)) process = psutil.Process(int(pid))
except psutil.NoSuchProcess, psutil.AccessDenied, ValueError: except (psutil.NoSuchProcess, psutil.AccessDenied, ValueError):
return None return None
try: try:
@@ -92,7 +92,7 @@ def _get_process(runtime: Optional[Dict[str, Any]] = None) -> Optional[psutil.Pr
return None return None
if not process.is_running() or process.status() == psutil.STATUS_ZOMBIE: if not process.is_running() or process.status() == psutil.STATUS_ZOMBIE:
return None return None
except psutil.NoSuchProcess, psutil.AccessDenied, psutil.ZombieProcess: except (psutil.NoSuchProcess, psutil.AccessDenied, psutil.ZombieProcess):
return None return None
return process return process
@@ -211,7 +211,7 @@ def _frontend_health(
with urlopen(request, timeout=timeout) as response: with urlopen(request, timeout=timeout) as response:
raw = response.read().decode("utf-8", errors="replace").strip() raw = response.read().decode("utf-8", errors="replace").strip()
return response.status == 200, {"version": raw} return response.status == 200, {"version": raw}
except HTTPError, URLError: except (HTTPError, URLError):
return False, None return False, None
@@ -234,7 +234,7 @@ def _git_current_branch() -> Optional[str]:
cwd=str(_repo_root()), cwd=str(_repo_root()),
text=True, text=True,
).strip() ).strip()
except OSError, subprocess.CalledProcessError: except (OSError, subprocess.CalledProcessError):
return None return None
return branch or None return branch or None
+1 -1
View File
@@ -77,7 +77,7 @@ class SchedulerCatalogOwner(_SchedulerOwnerBase):
return None return None
try: try:
interval = int(interval) interval = int(interval)
except TypeError, ValueError: except (TypeError, ValueError):
return None return None
return interval if interval > 0 else None return interval if interval > 0 else None
+1 -1
View File
@@ -132,7 +132,7 @@ class SchedulerExecutionOwner(_SchedulerOwnerBase):
""" """
try: try:
parameters = inspect.signature(func).parameters parameters = inspect.signature(func).parameters
except TypeError, ValueError: except (TypeError, ValueError):
return False return False
return "progress_callback" in parameters return "progress_callback" in parameters
+2 -2
View File
@@ -136,7 +136,7 @@ class SchedulerProgressOwner(_SchedulerOwnerBase):
value = detail.get("value", 0) value = detail.get("value", 0)
try: try:
value = float(value) value = float(value)
except TypeError, ValueError: except (TypeError, ValueError):
value = 0.0 value = 0.0
return _SchemaScheduleProgress( return _SchemaScheduleProgress(
id=job_id, id=job_id,
@@ -179,7 +179,7 @@ class SchedulerProgressOwner(_SchedulerOwnerBase):
value = detail.get("value", 0) value = detail.get("value", 0)
try: try:
value = float(value) value = float(value)
except TypeError, ValueError: except (TypeError, ValueError):
value = 0.0 value = 0.0
return _SchemaScheduleProgress( return _SchemaScheduleProgress(
id=job_id, id=job_id,
+1 -1
View File
@@ -228,7 +228,7 @@ class SchedulerReconcileOwner(_SchedulerOwnerBase):
trigger_value=trigger_value, trigger_value=trigger_value,
timezone_name=config.timezone, timezone_name=config.timezone,
) )
except TypeError, ValueError: except (TypeError, ValueError):
return None return None
return next_run_time.isoformat(timespec="seconds") if next_run_time else None return next_run_time.isoformat(timespec="seconds") if next_run_time else None
@@ -386,7 +386,7 @@ def _jsonable(value: Any, *, depth: int = 0) -> Any:
return _jsonable(data, depth=depth + 1) return _jsonable(data, depth=depth + 1)
try: try:
return _jsonable(dict(value), depth=depth + 1) return _jsonable(dict(value), depth=depth + 1)
except TypeError, ValueError: except (TypeError, ValueError):
return str(value) return str(value)