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 consider-iterating-dictionary lint rule and updates #12366

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion qiskit/circuit/library/n_local/pauli_two_design.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions qiskit/pulse/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion qiskit/synthesis/discrete_basis/solovay_kitaev.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions qiskit/transpiler/passes/synthesis/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 []
Expand Down
2 changes: 1 addition & 1 deletion qiskit/visualization/circuit/matplotlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down
4 changes: 2 additions & 2 deletions qiskit/visualization/circuit/qcstyle.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Comment on lines -75 to 76
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Entirely unimportant, but this can also be spelled

key = self.ABBREVIATIONS.get(key, key)


if key not in self.VALID_FIELDS:
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions test/python/transpiler/test_high_level_synthesis.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 []
Expand Down
Loading