fix: replace 11 bare except clauses with except Exception

This commit is contained in:
haosenwang1018 2026-02-26 00:56:05 +00:00
parent 84814b2a72
commit 023dd64f69
10 changed files with 11 additions and 11 deletions

View File

@ -237,7 +237,7 @@ async def check(predicate, generator):
if not await predicate(case):
reduction = await reduce(case, predicate)
counter_examples.append("after {} reductions: {!r}".format(*reduction))
except:
except Exception:
counter_examples.append(f"{case!r} : {traceback.format_exc()}")
return counter_examples

View File

@ -248,7 +248,7 @@ class TestBSONFallbackEncoder(unittest.TestCase):
def fallback_encoder(value):
try:
return Decimal128(value)
except:
except Exception:
raise TypeError("cannot encode type %s" % (type(value)))
codecopts = self._get_codec_options(fallback_encoder)

View File

@ -153,7 +153,7 @@ class TestMongosLoadBalancing(AsyncMockClientTest):
client.kill_host("{}:{}".format(*next(iter(client.nodes))))
try:
await client.db.command("ping")
except:
except Exception:
pass
# We eventually connect to a new mongos.

View File

@ -858,7 +858,7 @@ class TestCausalConsistency(AsyncUnitTest):
self.listener.reset()
try:
await self.client.pymongo_test.command("doesntexist", session=sess)
except:
except Exception:
pass
failed = self.listener.failed_events[0]
failed_op_time = failed.failure.get("operationTime")

View File

@ -43,7 +43,7 @@ try:
from mod_wsgi import version as mod_wsgi_version # type: ignore[import]
_HAVE_MOD_WSGI = True
except:
except Exception:
mod_wsgi_version = None
_HAVE_MOD_WSGI = False

View File

@ -237,7 +237,7 @@ def check(predicate, generator):
if not predicate(case):
reduction = reduce(case, predicate)
counter_examples.append("after {} reductions: {!r}".format(*reduction))
except:
except Exception:
counter_examples.append(f"{case!r} : {traceback.format_exc()}")
return counter_examples

View File

@ -248,7 +248,7 @@ class TestBSONFallbackEncoder(unittest.TestCase):
def fallback_encoder(value):
try:
return Decimal128(value)
except:
except Exception:
raise TypeError("cannot encode type %s" % (type(value)))
codecopts = self._get_codec_options(fallback_encoder)

View File

@ -153,7 +153,7 @@ class TestMongosLoadBalancing(MockClientTest):
client.kill_host("{}:{}".format(*next(iter(client.nodes))))
try:
client.db.command("ping")
except:
except Exception:
pass
# We eventually connect to a new mongos.

View File

@ -858,7 +858,7 @@ class TestCausalConsistency(UnitTest):
self.listener.reset()
try:
self.client.pymongo_test.command("doesntexist", session=sess)
except:
except Exception:
pass
failed = self.listener.failed_events[0]
failed_op_time = failed.failure.get("operationTime")

View File

@ -72,7 +72,7 @@ class Insert(threading.Thread):
try:
self.collection.insert_one({"test": "insert"})
error = False
except:
except Exception:
if not self.expect_exception:
raise
@ -95,7 +95,7 @@ class Update(threading.Thread):
try:
self.collection.update_one({"test": "unique"}, {"$set": {"test": "update"}})
error = False
except:
except Exception:
if not self.expect_exception:
raise