diff --git a/pyproject.toml b/pyproject.toml index 303192e75cf9..45725f51bb48 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -218,7 +218,6 @@ disable = [ # with the rationale "arguments-renamed", "broad-exception-raised", - "consider-iterating-dictionary", "consider-using-dict-items", "consider-using-enumerate", "consider-using-f-string", diff --git a/qiskit/circuit/library/n_local/pauli_two_design.py b/qiskit/circuit/library/n_local/pauli_two_design.py index b79f08889387..71b090d08848 100644 --- a/qiskit/circuit/library/n_local/pauli_two_design.py +++ b/qiskit/circuit/library/n_local/pauli_two_design.py @@ -118,7 +118,7 @@ def _build_rotation_layer(self, circuit, param_iter, i): qubits = range(self.num_qubits) # if no gates for this layer were generated, generate them - if i not in self._gates.keys(): + if i not in self._gates: self._gates[i] = list(self._rng.choice(["rx", "ry", "rz"], self.num_qubits)) # if not enough gates exist, add more elif len(self._gates[i]) < self.num_qubits: diff --git a/qiskit/pulse/parser.py b/qiskit/pulse/parser.py index a9e752f562e5..8e31faebf77a 100644 --- a/qiskit/pulse/parser.py +++ b/qiskit/pulse/parser.py @@ -120,7 +120,7 @@ def __call__(self, *args, **kwargs) -> complex | ast.Expression | PulseExpressio if kwargs: for key, val in kwargs.items(): if key in self.params: - if key not in self._locals_dict.keys(): + if key not in self._locals_dict: self._locals_dict[key] = val else: raise PulseError( @@ -272,7 +272,7 @@ def visit_Call(self, node: ast.Call) -> ast.Call | ast.Constant: node = copy.copy(node) node.args = [self.visit(arg) for arg in node.args] if all(isinstance(arg, ast.Constant) for arg in node.args): - if node.func.id not in self._math_ops.keys(): + if node.func.id not in self._math_ops: raise PulseError("Function %s is not supported." % node.func.id) _args = [arg.value for arg in node.args] _val = self._math_ops[node.func.id](*_args) diff --git a/qiskit/synthesis/discrete_basis/generate_basis_approximations.py b/qiskit/synthesis/discrete_basis/generate_basis_approximations.py index 07139b223b1d..672d0eb9e8ef 100644 --- a/qiskit/synthesis/discrete_basis/generate_basis_approximations.py +++ b/qiskit/synthesis/discrete_basis/generate_basis_approximations.py @@ -137,7 +137,7 @@ def generate_basic_approximations( basis = [] for gate in basis_gates: if isinstance(gate, str): - if gate not in _1q_gates.keys(): + if gate not in _1q_gates: raise ValueError(f"Invalid gate identifier: {gate}") basis.append(gate) else: # gate is a qiskit.circuit.Gate diff --git a/qiskit/synthesis/discrete_basis/solovay_kitaev.py b/qiskit/synthesis/discrete_basis/solovay_kitaev.py index 62ad50582d40..e1db47beaeff 100644 --- a/qiskit/synthesis/discrete_basis/solovay_kitaev.py +++ b/qiskit/synthesis/discrete_basis/solovay_kitaev.py @@ -180,7 +180,7 @@ def _remove_inverse_follows_gate(sequence): while index < len(sequence.gates) - 1: curr_gate = sequence.gates[index] next_gate = sequence.gates[index + 1] - if curr_gate.name in _1q_inverses.keys(): + if curr_gate.name in _1q_inverses: remove = _1q_inverses[curr_gate.name] == next_gate.name else: remove = curr_gate.inverse() == next_gate diff --git a/qiskit/transpiler/passes/synthesis/plugin.py b/qiskit/transpiler/passes/synthesis/plugin.py index f2485bfee530..c57c6d76f9fb 100644 --- a/qiskit/transpiler/passes/synthesis/plugin.py +++ b/qiskit/transpiler/passes/synthesis/plugin.py @@ -698,13 +698,13 @@ def __init__(self): self.plugins_by_op = {} for plugin_name in self.plugins.names(): op_name, method_name = plugin_name.split(".") - if op_name not in self.plugins_by_op.keys(): + if op_name not in self.plugins_by_op: self.plugins_by_op[op_name] = [] self.plugins_by_op[op_name].append(method_name) def method_names(self, op_name): """Returns plugin methods for op_name.""" - if op_name in self.plugins_by_op.keys(): + if op_name in self.plugins_by_op: return self.plugins_by_op[op_name] else: return [] diff --git a/qiskit/visualization/circuit/matplotlib.py b/qiskit/visualization/circuit/matplotlib.py index c547846acc5b..b4252065006c 100644 --- a/qiskit/visualization/circuit/matplotlib.py +++ b/qiskit/visualization/circuit/matplotlib.py @@ -893,7 +893,7 @@ def _draw_regs_wires(self, num_folds, xmax, max_x_index, qubits_dict, clbits_dic this_clbit_dict = {} for clbit in clbits_dict.values(): y = clbit["y"] - fold_num * (glob_data["n_lines"] + 1) - if y not in this_clbit_dict.keys(): + if y not in this_clbit_dict: this_clbit_dict[y] = { "val": 1, "wire_label": clbit["wire_label"], diff --git a/qiskit/visualization/circuit/qcstyle.py b/qiskit/visualization/circuit/qcstyle.py index a8432ca86a9e..67ae9faaf24b 100644 --- a/qiskit/visualization/circuit/qcstyle.py +++ b/qiskit/visualization/circuit/qcstyle.py @@ -72,7 +72,7 @@ class StyleDict(dict): def __setitem__(self, key: Any, value: Any) -> None: # allow using field abbreviations - if key in self.ABBREVIATIONS.keys(): + if key in self.ABBREVIATIONS: key = self.ABBREVIATIONS[key] if key not in self.VALID_FIELDS: @@ -85,7 +85,7 @@ def __setitem__(self, key: Any, value: Any) -> None: def __getitem__(self, key: Any) -> Any: # allow using field abbreviations - if key in self.ABBREVIATIONS.keys(): + if key in self.ABBREVIATIONS: key = self.ABBREVIATIONS[key] return super().__getitem__(key) diff --git a/test/python/transpiler/test_high_level_synthesis.py b/test/python/transpiler/test_high_level_synthesis.py index 9a2432b82f9c..f20b102d1838 100644 --- a/test/python/transpiler/test_high_level_synthesis.py +++ b/test/python/transpiler/test_high_level_synthesis.py @@ -126,7 +126,7 @@ class OpARepeatSynthesisPlugin(HighLevelSynthesisPlugin): """The repeat synthesis for opA""" def run(self, high_level_object, coupling_map=None, target=None, qubits=None, **options): - if "n" not in options.keys(): + if "n" not in options: return None qc = QuantumCircuit(1) @@ -206,7 +206,7 @@ def __init__(self): def method_names(self, op_name): """Returns plugin methods for op_name.""" - if op_name in self.plugins_by_op.keys(): + if op_name in self.plugins_by_op: return self.plugins_by_op[op_name] else: return []