Skip to content

Commit 3888bb9

Browse files
authored
Merge pull request #3367 from haosenwang1018/fix/bare-excepts
fix: replace 34 bare except clauses with except Exception
2 parents 0ca5a67 + 4ac78c9 commit 3888bb9

File tree

19 files changed

+34
-34
lines changed

19 files changed

+34
-34
lines changed

etc/testing/test_all.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ async def test(model: g4f.Model):
1818
print(response, end="")
1919

2020
print()
21-
except:
21+
except Exception:
2222
for response in await g4f.ChatCompletion.create_async(
2323
model=model,
2424
messages=[{"role": "user", "content": "write a poem about a tree"}],

etc/tool/commit.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ def get_repository_info(repo_path: Path) -> dict:
201201
)
202202
if branch_process.returncode == 0:
203203
info["branch"] = branch_process.stdout.strip()
204-
except:
204+
except Exception:
205205
pass
206206

207207
try:
@@ -214,7 +214,7 @@ def get_repository_info(repo_path: Path) -> dict:
214214
)
215215
if remote_process.returncode == 0:
216216
info["remote"] = remote_process.stdout.strip()
217-
except:
217+
except Exception:
218218
pass
219219

220220
return info
@@ -287,7 +287,7 @@ def spin():
287287
time.sleep(duration)
288288
stop_spinner.set()
289289
return stop_spinner
290-
except:
290+
except Exception:
291291
stop_spinner.set()
292292
raise
293293

@@ -383,7 +383,7 @@ def edit_commit_message(message: str) -> str:
383383
["git", "config", "--get", "core.editor"],
384384
capture_output=True, text=True
385385
).stdout.strip()
386-
except:
386+
except Exception:
387387
editor = os.environ.get('EDITOR', 'vim')
388388

389389
if not editor:

etc/tool/readme_table.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def print_providers():
9999
lines.append(f"| **Image Models (Image Generation)** | {', '.join(image_models)} |")
100100
if hasattr(_provider, "vision_models"):
101101
lines.append(f"| **Vision (Image Upload)** | ✔️ |")
102-
except:
102+
except Exception:
103103
pass
104104

105105
lines.append(f"| **Authentication** | {auth} | \n| **Streaming** | {stream} |")

etc/unittest/asyncio.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
try:
33
import nest_asyncio2 as nest_asyncio
44
has_nest_asyncio = True
5-
except:
5+
except Exception:
66
has_nest_asyncio = False
77
import unittest
88

etc/unittest/backend.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
try:
88
from g4f.gui.server.backend_api import Backend_Api
99
has_requirements = True
10-
except:
10+
except Exception:
1111
has_requirements = False
1212
try:
1313
from g4f.tools.web_search import search
1414
has_search = True
15-
except:
15+
except Exception:
1616
has_search = False
1717
try:
1818
from ddgs.exceptions import DDGSException

g4f/Provider/Copilot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ async def create_authed(
286286
try:
287287
msg_txt, _ = await asyncio.wait_for(wss.recv(), 1 if done else timeout)
288288
msg = json.loads(msg_txt)
289-
except:
289+
except Exception:
290290
break
291291
last_msg = msg
292292
if msg.get("event") == "appendText":

g4f/Provider/CopilotSession.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ async def create_authed(
168168
try:
169169
request_id, msg_txt = await asyncio.wait_for(queue.get(), 1 if done else timeout)
170170
msg = json.loads(msg_txt)
171-
except:
171+
except Exception:
172172
break
173173
last_msg = msg
174174
if msg.get("event") == "startMessage":

g4f/Provider/needs_auth/LMArena.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ async def create_async_generator(
614614
force = True
615615
debug.error(error)
616616
continue
617-
except:
617+
except Exception:
618618
raise
619619
if args and os.getenv("G4F_SHARE_AUTH") and not kwargs.get("action"):
620620
yield "\n" * 10

g4f/Provider/needs_auth/OpenaiChat.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,7 @@ def products_replacer(match: re.Match[str]):
648648
products_str += f"{name} - {tags}\n\n"
649649

650650
return products_str
651-
except:
651+
except Exception:
652652
return ""
653653

654654
sequence_content = match.group(1)
@@ -747,7 +747,7 @@ async def wss_media(
747747
while not wss.closed:
748748
try:
749749
last_msg = await wss.recv_json(timeout=60 if not started else timeout)
750-
except:
750+
except Exception:
751751
break
752752
conversation_id = conversation.task.get("conversation_id")
753753
message_id = conversation.task.get("message", {}).get("id")
@@ -871,7 +871,7 @@ async def iter_messages_line(cls, session: StreamSession, auth_result: AuthResul
871871
return
872872
try:
873873
line = json.loads(line[6:])
874-
except:
874+
except Exception:
875875
return
876876
if not isinstance(line, dict):
877877
return

g4f/Provider/needs_auth/Video.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import zendriver as nodriver
1313
from zendriver.core.connection import ProtocolException
1414
has_nodriver = True
15-
except:
15+
except Exception:
1616
has_nodriver = False
1717

1818
from ...typing import Messages, AsyncResult

0 commit comments

Comments
 (0)