Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removing broad-exception-raised lint rule and updates #12356

Merged
merged 6 commits into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,6 @@ disable = [
# remove from here and fix the issues. Else, move it above this section and add a comment
# with the rationale
"arguments-renamed",
"broad-exception-raised",
"consider-iterating-dictionary",
"consider-using-dict-items",
"consider-using-enumerate",
Expand Down
2 changes: 1 addition & 1 deletion qiskit/quantum_info/quaternion.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def __mul__(self, r):
out_data[3] = r(0) * q(3) - r(1) * q(2) + r(2) * q(1) + r(3) * q(0)
return Quaternion(out_data)
else:
raise Exception("Multiplication by other not supported.")
raise RuntimeError("Multiplication by other not supported.")
jakelishman marked this conversation as resolved.
Show resolved Hide resolved

def norm(self):
"""Norm of quaternion."""
Expand Down
2 changes: 1 addition & 1 deletion qiskit/synthesis/clifford/clifford_decompose_bm.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def _cx_cost(clifford):
return _cx_cost2(clifford)
if clifford.num_qubits == 3:
return _cx_cost3(clifford)
raise Exception("No Clifford CX cost function for num_qubits > 3.")
raise RuntimeError("No Clifford CX cost function for num_qubits > 3.")


def _rank2(a, b, c, d):
Expand Down
4 changes: 2 additions & 2 deletions qiskit/visualization/bloch.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ def set_label_convention(self, convention):
self.zlabel = ["$\\circlearrowleft$", "$\\circlearrowright$"]
self.xlabel = ["$\\leftrightarrow$", "$\\updownarrow$"]
else:
raise Exception("No such convention.")
raise NotImplementedError("No such convention.")
jakelishman marked this conversation as resolved.
Show resolved Hide resolved

def __str__(self):
string = ""
Expand Down Expand Up @@ -396,7 +396,7 @@ def add_annotation(self, state_or_vector, text, **kwargs):
if isinstance(state_or_vector, (list, np.ndarray, tuple)) and len(state_or_vector) == 3:
vec = state_or_vector
else:
raise Exception("Position needs to be specified by a qubit " + "state or a 3D vector.")
raise RuntimeError("Position needs to be specified by a qubit state or a 3D vector.")
jakelishman marked this conversation as resolved.
Show resolved Hide resolved
self.annotations.append({"position": vec, "text": text, "opts": kwargs})

def make_sphere(self):
Expand Down
4 changes: 2 additions & 2 deletions qiskit/visualization/transition_visualization.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ def __mul__(self, b):
return self._multiply_with_quaternion(b)
elif isinstance(b, (list, tuple, np.ndarray)):
if len(b) != 3:
raise Exception(f"Input vector has invalid length {len(b)}")
raise RuntimeError(f"Input vector has invalid length {len(b)}")
jakelishman marked this conversation as resolved.
Show resolved Hide resolved
return self._multiply_with_vector(b)
else:
raise Exception(f"Multiplication with unknown type {type(b)}")
raise TypeError(f"Multiplication with unknown type {type(b)}")
jakelishman marked this conversation as resolved.
Show resolved Hide resolved

def _multiply_with_quaternion(self, q_2):
"""Multiplication of quaternion with quaternion"""
Expand Down
2 changes: 1 addition & 1 deletion test/benchmarks/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def random_circuit(
Exception: when invalid options given
"""
if max_operands < 1 or max_operands > 3:
raise Exception("max_operands must be between 1 and 3")
raise RuntimeError("max_operands must be between 1 and 3")
jakelishman marked this conversation as resolved.
Show resolved Hide resolved

one_q_ops = [
IGate,
Expand Down
2 changes: 1 addition & 1 deletion test/python/transpiler/test_preset_passmanagers.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def mock_get_passmanager_stage(
elif stage_name == "layout":
return PassManager([])
else:
raise Exception("Failure, unexpected stage plugin combo for test")
raise RuntimeError("Failure, unexpected stage plugin combo for test")


def emptycircuit():
Expand Down
2 changes: 1 addition & 1 deletion test/python/transpiler/test_sabre_swap.py
Original file line number Diff line number Diff line change
Expand Up @@ -1346,7 +1346,7 @@ def _visit_block(circuit, qubit_mapping=None):
qargs = tuple(qubit_mapping[x] for x in instruction.qubits)
if not isinstance(instruction.operation, ControlFlowOp):
if len(qargs) > 2 or len(qargs) < 0:
raise Exception("Invalid number of qargs for instruction")
raise RuntimeError("Invalid number of qargs for instruction")
if len(qargs) == 2:
self.assertIn(qargs, self.coupling_edge_set)
else:
Expand Down
2 changes: 1 addition & 1 deletion test/python/transpiler/test_stochastic_swap.py
Original file line number Diff line number Diff line change
Expand Up @@ -1506,7 +1506,7 @@ def _visit_block(circuit, qubit_mapping=None):
qargs = tuple(qubit_mapping[x] for x in instruction.qubits)
if not isinstance(instruction.operation, ControlFlowOp):
if len(qargs) > 2 or len(qargs) < 0:
raise Exception("Invalid number of qargs for instruction")
raise RuntimeError("Invalid number of qargs for instruction")
if len(qargs) == 2:
self.assertIn(qargs, self.coupling_edge_set)
else:
Expand Down