XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet
公开
关注 0 Fork 0 Star 0
返回提交历史

XFEstudio/gpt4free

fix: replace bare except clauses with except Exception

Bare `except:` catches BaseException including KeyboardInterrupt and SystemExit. Replaced 34 instances with `except Exception:`.

4ac78c9e
haosenwang1018 <haosenwang1018@users.noreply.github.com>
提交于

代码差异

19 个文件 +34 -34
Modified etc/testing/test_all.py +1 -1
@@ -18,7 +18,7 @@ async def test(model: g4f.Model):
18 18 print(response, end="")
19 19
20 20 print()
21 except:
21 except Exception:
22 22 for response in await g4f.ChatCompletion.create_async(
23 23 model=model,
24 24 messages=[{"role": "user", "content": "write a poem about a tree"}],
Modified etc/tool/commit.py +4 -4
@@ -201,7 +201,7 @@ def get_repository_info(repo_path: Path) -> dict:
201 201 )
202 202 if branch_process.returncode == 0:
203 203 info["branch"] = branch_process.stdout.strip()
204 except:
204 except Exception:
205 205 pass
206 206
207 207 try:
@@ -214,7 +214,7 @@ def get_repository_info(repo_path: Path) -> dict:
214 214 )
215 215 if remote_process.returncode == 0:
216 216 info["remote"] = remote_process.stdout.strip()
217 except:
217 except Exception:
218 218 pass
219 219
220 220 return info
@@ -287,7 +287,7 @@ def show_spinner(duration: int = None):
287 287 time.sleep(duration)
288 288 stop_spinner.set()
289 289 return stop_spinner
290 except:
290 except Exception:
291 291 stop_spinner.set()
292 292 raise
293 293
@@ -383,7 +383,7 @@ def edit_commit_message(message: str) -> str:
383 383 ["git", "config", "--get", "core.editor"],
384 384 capture_output=True, text=True
385 385 ).stdout.strip()
386 except:
386 except Exception:
387 387 editor = os.environ.get('EDITOR', 'vim')
388 388
389 389 if not editor:
Modified etc/tool/readme_table.py +1 -1
@@ -99,7 +99,7 @@ def print_providers():
99 99 lines.append(f"| **Image Models (Image Generation)** | {', '.join(image_models)} |")
100 100 if hasattr(_provider, "vision_models"):
101 101 lines.append(f"| **Vision (Image Upload)** | ✔️ |")
102 except:
102 except Exception:
103 103 pass
104 104
105 105 lines.append(f"| **Authentication** | {auth} | \n| **Streaming** | {stream} |")
Modified etc/unittest/asyncio.py +1 -1
@@ -2,7 +2,7 @@ import asyncio
2 2 try:
3 3 import nest_asyncio2 as nest_asyncio
4 4 has_nest_asyncio = True
5 except:
5 except Exception:
6 6 has_nest_asyncio = False
7 7 import unittest
8 8
Modified etc/unittest/backend.py +2 -2
@@ -7,12 +7,12 @@ from g4f.errors import MissingRequirementsError
7 7 try:
8 8 from g4f.gui.server.backend_api import Backend_Api
9 9 has_requirements = True
10 except:
10 except Exception:
11 11 has_requirements = False
12 12 try:
13 13 from g4f.tools.web_search import search
14 14 has_search = True
15 except:
15 except Exception:
16 16 has_search = False
17 17 try:
18 18 from ddgs.exceptions import DDGSException
Modified g4f/Provider/Copilot.py +1 -1
@@ -286,7 +286,7 @@ class Copilot(AsyncAuthedProvider, ProviderModelMixin):
286 286 try:
287 287 msg_txt, _ = await asyncio.wait_for(wss.recv(), 1 if done else timeout)
288 288 msg = json.loads(msg_txt)
289 except:
289 except Exception:
290 290 break
291 291 last_msg = msg
292 292 if msg.get("event") == "appendText":
Modified g4f/Provider/CopilotSession.py +1 -1
@@ -168,7 +168,7 @@ class CopilotSession(AsyncAuthedProvider, ProviderModelMixin):
168 168 try:
169 169 request_id, msg_txt = await asyncio.wait_for(queue.get(), 1 if done else timeout)
170 170 msg = json.loads(msg_txt)
171 except:
171 except Exception:
172 172 break
173 173 last_msg = msg
174 174 if msg.get("event") == "startMessage":
Modified g4f/Provider/needs_auth/LMArena.py +1 -1
@@ -614,7 +614,7 @@ class LMArena(AsyncGeneratorProvider, ProviderModelMixin, AuthFileMixin):
614 614 force = True
615 615 debug.error(error)
616 616 continue
617 except:
617 except Exception:
618 618 raise
619 619 if args and os.getenv("G4F_SHARE_AUTH") and not kwargs.get("action"):
620 620 yield "\n" * 10
Modified g4f/Provider/needs_auth/OpenaiChat.py +3 -3
@@ -648,7 +648,7 @@ class OpenaiChat(AsyncAuthedProvider, ProviderModelMixin):
648 648 products_str += f"{name} - {tags}\n\n"
649 649
650 650 return products_str
651 except:
651 except Exception:
652 652 return ""
653 653
654 654 sequence_content = match.group(1)
@@ -747,7 +747,7 @@ class OpenaiChat(AsyncAuthedProvider, ProviderModelMixin):
747 747 while not wss.closed:
748 748 try:
749 749 last_msg = await wss.recv_json(timeout=60 if not started else timeout)
750 except:
750 except Exception:
751 751 break
752 752 conversation_id = conversation.task.get("conversation_id")
753 753 message_id = conversation.task.get("message", {}).get("id")
@@ -871,7 +871,7 @@ class OpenaiChat(AsyncAuthedProvider, ProviderModelMixin):
871 871 return
872 872 try:
873 873 line = json.loads(line[6:])
874 except:
874 except Exception:
875 875 return
876 876 if not isinstance(line, dict):
877 877 return
Modified g4f/Provider/needs_auth/Video.py +1 -1
@@ -12,7 +12,7 @@ try:
12 12 import zendriver as nodriver
13 13 from zendriver.core.connection import ProtocolException
14 14 has_nodriver = True
15 except:
15 except Exception:
16 16 has_nodriver = False
17 17
18 18 from ...typing import Messages, AsyncResult
Modified g4f/Provider/needs_auth/bing/create_images.py +1 -1
@@ -118,7 +118,7 @@ async def create_images(session: ClientSession, prompt: str, timeout: int = TIME
118 118 error = None
119 119 try:
120 120 error = json.loads(text).get("errorMessage")
121 except:
121 except Exception:
122 122 pass
123 123 if error == "Pending":
124 124 raise RuntimeError("Prompt is been blocked")
Modified g4f/Provider/needs_auth/hf/HuggingFaceMedia.py +1 -1
@@ -227,7 +227,7 @@ class HuggingFaceMedia(AsyncGeneratorProvider, ProviderModelMixin):
227 227 item["url"] if isinstance(item, dict) else item
228 228 for item in result.get("images", result.get("data", result.get("output")))
229 229 ], prompt)
230 except:
230 except Exception:
231 231 raise ValueError(f"Unexpected response: {result}")
232 232 elif task == "text-to-video" and result.get("output") is not None:
233 233 return provider_info, VideoResponse(result["output"], prompt)
Modified g4f/Provider/qwen/QwenCode.py +1 -1
Modified g4f/Provider/qwen/oauthFlow.py +1 -1
Modified g4f/Provider/qwen/sharedTokenManager.py +5 -5
Modified g4f/api/__init__.py +3 -3
Modified g4f/requests/__init__.py +3 -3
Modified g4f/tools/files.py +1 -1
Modified g4f/tools/run_tools.py +2 -2