This is an automated email from the ASF dual-hosted git repository.
ruihangl pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tvm.git
The following commit(s) were added to refs/heads/main by this push:
new 7b771ce623 fix: replace 6 bare except clauses with except Exception
(#18821)
7b771ce623 is described below
commit 7b771ce6230095268ac5f1d31af34b3f6e2a6888
Author: Sense_wang <[email protected]>
AuthorDate: Thu Feb 26 23:49:11 2026 +0800
fix: replace 6 bare except clauses with except Exception (#18821)
## What
Replace 6 bare `except:` clauses with `except Exception:`.
## Why
Bare `except:` catches `BaseException`, including `KeyboardInterrupt`
and `SystemExit`, which can prevent clean process shutdown and mask
critical errors. Using `except Exception:` catches all application-level
errors while allowing system-level exceptions to propagate correctly.
---
python/tvm/relax/frontend/torch/fx_translator.py | 2 +-
python/tvm/runtime/_tensor.py | 2 +-
python/tvm/s_tir/dlight/analysis/common_analysis.py | 2 +-
tests/python/contrib/test_hexagon/test_run_unit_tests.py | 2 +-
tests/python/relax/test_group_gemm_flashinfer.py | 2 +-
tests/scripts/release/make_notes.py | 2 +-
6 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/python/tvm/relax/frontend/torch/fx_translator.py
b/python/tvm/relax/frontend/torch/fx_translator.py
index 74ffebd823..5fd414d3f4 100644
--- a/python/tvm/relax/frontend/torch/fx_translator.py
+++ b/python/tvm/relax/frontend/torch/fx_translator.py
@@ -1232,7 +1232,7 @@ def from_fx(
# Use the dynamo.export() to export the PyTorch model to FX.
try:
graph_module = dynamo.export(torch_model, *input_tensors)
- except:
+ except Exception:
raise RuntimeError("Failed to export the PyTorch model to FX.")
# Use the importer to import the PyTorch model to Relax.
diff --git a/python/tvm/runtime/_tensor.py b/python/tvm/runtime/_tensor.py
index d5810094b5..9eea8a36d2 100644
--- a/python/tvm/runtime/_tensor.py
+++ b/python/tvm/runtime/_tensor.py
@@ -111,7 +111,7 @@ class Tensor(tvm_ffi.core.Tensor):
if not isinstance(source_array, np.ndarray):
try:
source_array = np.array(source_array, dtype=self.dtype)
- except:
+ except Exception:
raise TypeError(
f"array must be an array_like data, type
{type(source_array)} is not supported"
)
diff --git a/python/tvm/s_tir/dlight/analysis/common_analysis.py
b/python/tvm/s_tir/dlight/analysis/common_analysis.py
index 2ec12b26c0..fb44d3fcea 100644
--- a/python/tvm/s_tir/dlight/analysis/common_analysis.py
+++ b/python/tvm/s_tir/dlight/analysis/common_analysis.py
@@ -377,7 +377,7 @@ def get_max_shared_memory_per_block(target: Target) -> int:
def get_root_block(sch: Schedule, func_name: str = "main") -> SBlockRV:
try:
block = sch.mod[func_name].body.block
- except:
+ except Exception:
raise ValueError(
f"The function body is expected to be the root block, but got:\n"
f"{sch.mod[func_name].body}"
diff --git a/tests/python/contrib/test_hexagon/test_run_unit_tests.py
b/tests/python/contrib/test_hexagon/test_run_unit_tests.py
index 1e82d6a20b..a7795813cd 100644
--- a/tests/python/contrib/test_hexagon/test_run_unit_tests.py
+++ b/tests/python/contrib/test_hexagon/test_run_unit_tests.py
@@ -151,7 +151,7 @@ def test_run_unit_tests(hexagon_session: Session,
gtest_args, unit_test_name):
"""Try running gtest unit tests and capture output and error code"""
try:
func = hexagon_session._rpc.get_function("hexagon.run_unit_tests")
- except:
+ except Exception:
print(
"This test requires TVM Runtime to be built with a Hexagon gtest"
"version using Hexagon API cmake flag"
diff --git a/tests/python/relax/test_group_gemm_flashinfer.py
b/tests/python/relax/test_group_gemm_flashinfer.py
index 39ae8d5a30..c128fdb35b 100644
--- a/tests/python/relax/test_group_gemm_flashinfer.py
+++ b/tests/python/relax/test_group_gemm_flashinfer.py
@@ -58,7 +58,7 @@ def has_cutlass():
handle = pynvml.nvmlDeviceGetHandleByIndex(0)
major, minor = pynvml.nvmlDeviceGetCudaComputeCapability(handle)
return major >= 9 # SM90+
- except:
+ except Exception:
return False
diff --git a/tests/scripts/release/make_notes.py
b/tests/scripts/release/make_notes.py
index 82def8adc2..b599f4b4f3 100644
--- a/tests/scripts/release/make_notes.py
+++ b/tests/scripts/release/make_notes.py
@@ -218,7 +218,7 @@ if __name__ == "__main__":
try:
title = pr_dict[int(number)]["title"]
title = strip_header(title, heading)
- except:
+ except Exception:
sprint("The out.pkl file is not match with csv file.")
exit(1)
return title