Skip to content

Commit 118de18

Browse files
authored
ruff - enable and fix ISC, implicit string concatenation (#7511)
- Enable ruff rule ISC for implicit string concatenation - Fix word-break across concatenated strings - ruff - fix ISC - implicit string concatenation issues - also fix pytest warning on always-matching empty pattern No change in the effective code. Partially implements #7505
1 parent cb60bba commit 118de18

File tree

20 files changed

+32
-37
lines changed

20 files changed

+32
-37
lines changed

cirq-aqt/cirq_aqt/aqt_device_metadata.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ def __init__(
5656
cirq.GateFamily(cirq.ZPowGate): self._oneq_gates_duration,
5757
cirq.GateFamily(cirq.PhasedXPowGate): self._oneq_gates_duration,
5858
}
59-
assert not self._gateset.gates.symmetric_difference(self._gate_durations.keys()), (
60-
"AQTDeviceMetadata.gate_durations must have the same Gates " "as AQTTargetGateset."
61-
)
59+
assert not self._gateset.gates.symmetric_difference(
60+
self._gate_durations.keys()
61+
), "AQTDeviceMetadata.gate_durations must have the same Gates as AQTTargetGateset."
6262

6363
@property
6464
def gateset(self) -> cirq.Gateset:

cirq-core/cirq/contrib/bayesian_network/bayesian_network_gate_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def test_repr() -> None:
5353

5454
assert repr(gate) == (
5555
"cirq.BayesianNetworkGate(init_probs=[('q0', 0.0), ('q1', None)],"
56-
+ " arc_probs=[('q1', ('q0',), [0.0, 0.0])])"
56+
" arc_probs=[('q1', ('q0',), [0.0, 0.0])])"
5757
)
5858

5959

cirq-core/cirq/contrib/paulistring/pauli_string_measurement_with_readout_mitigation_test.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -814,8 +814,7 @@ def test_group_paulis_are_not_qwc() -> None:
814814
circuits_to_pauli: dict[cirq.FrozenCircuit, list[cirq.PauliString]] = {}
815815
circuits_to_pauli[circuit] = [[pauli_str1, pauli_str2]] # type: ignore
816816
with pytest.raises(
817-
ValueError,
818-
match="The group of Pauli strings are not " "Qubit-Wise Commuting with each other.",
817+
ValueError, match="The group of Pauli strings are not Qubit-Wise Commuting with each other."
819818
):
820819
measure_pauli_strings(
821820
circuits_to_pauli, cirq.Simulator(), 1000, 1000, 1000, np.random.default_rng()

cirq-core/cirq/devices/insertion_noise_model.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ def noisy_moment(self, moment: cirq.Moment, system_qubits: Sequence[cirq.Qid]) -
7878
def __repr__(self) -> str:
7979
return (
8080
f'cirq.devices.InsertionNoiseModel(ops_added={self.ops_added},'
81-
+ f' prepend={self.prepend},'
82-
+ f' require_physical_tag={self.require_physical_tag})'
81+
f' prepend={self.prepend},'
82+
f' require_physical_tag={self.require_physical_tag})'
8383
)
8484

8585
def _json_dict_(self) -> dict[str, Any]:

cirq-core/cirq/experiments/readout_confusion_matrix.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,8 +347,8 @@ def readout_mitigation_pauli_uncorrelated(
347347
idx = self.measure_qubits.index((qubit,))
348348
except: # pragma: no cover
349349
raise NotImplementedError(
350-
"The response matrix must be a tensor product of single-qu"
351-
+ f"bit response matrices, including that of qubit {qubit}."
350+
"The response matrix must be a tensor product of single-qubit "
351+
f"response matrices, including that of qubit {qubit}."
352352
)
353353
cm_all.append(self.confusion_matrices[idx])
354354

cirq-core/cirq/ops/common_channels.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,8 @@ def _circuit_diagram_info_(self, args: protocols.CircuitDiagramInfoArgs) -> str
146146
if args.precision is not None:
147147
return (
148148
f"A({self.p_x:.{args.precision}g},"
149-
+ f"{self.p_y:.{args.precision}g},"
150-
+ f"{self.p_z:.{args.precision}g})"
149+
f"{self.p_y:.{args.precision}g},"
150+
f"{self.p_z:.{args.precision}g})"
151151
)
152152
return f"A({self.p_x},{self.p_y},{self.p_z})"
153153
if args.precision is not None:

cirq-core/cirq/ops/common_channels_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def test_asymmetric_depolarizing_channel_str() -> None:
8484
assert (
8585
str(cirq.asymmetric_depolarize(0.1, 0.2, 0.3))
8686
== "asymmetric_depolarize(error_probabilities={'I': 0.3999999999999999, "
87-
+ "'X': 0.1, 'Y': 0.2, 'Z': 0.3})"
87+
"'X': 0.1, 'Y': 0.2, 'Z': 0.3})"
8888
)
8989

9090

cirq-core/cirq/ops/projector.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ def expectation_from_density_matrix(
135135
def __repr__(self) -> str:
136136
return (
137137
f"cirq.ProjectorString(projector_dict={self._projector_dict},"
138-
+ f"coefficient={self._coefficient})"
138+
f"coefficient={self._coefficient})"
139139
)
140140

141141
def _json_dict_(self) -> dict[str, Any]:

cirq-core/cirq/protocols/json_serialization_test.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -549,9 +549,7 @@ def custom_resolver(name):
549549

550550
sto = SerializableTypeObject(cls)
551551
test_resolvers = [custom_resolver] + cirq.DEFAULT_RESOLVERS
552-
expected_json = (
553-
f'{{\n "cirq_type": "SerializableTypeObject",\n' f' "test_type": "{typename}"\n}}'
554-
)
552+
expected_json = f'{{\n "cirq_type": "SerializableTypeObject",\n "test_type": "{typename}"\n}}'
555553
assert cirq.to_json(sto) == expected_json
556554
assert cirq.read_json(json_text=expected_json, resolvers=test_resolvers) == sto
557555
assert_json_roundtrip_works(sto, resolvers=test_resolvers)

cirq-core/cirq/sim/clifford/clifford_simulator_test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ def test_clifford_trial_result_repr_pretty():
276276
final_simulator_state=final_simulator_state,
277277
)
278278

279-
cirq.testing.assert_repr_pretty(result, "measurements: m=1\n" "output state: |0⟩")
279+
cirq.testing.assert_repr_pretty(result, "measurements: m=1\noutput state: |0⟩")
280280
cirq.testing.assert_repr_pretty(result, "cirq.CliffordTrialResult(...)", cycle=True)
281281

282282

@@ -285,15 +285,15 @@ def test_clifford_step_result_str():
285285
result = next(
286286
cirq.CliffordSimulator().simulate_moment_steps(cirq.Circuit(cirq.measure(q0, key='m')))
287287
)
288-
assert str(result) == "m=0\n" "|0⟩"
288+
assert str(result) == "m=0\n|0⟩"
289289

290290

291291
def test_clifford_step_result_repr_pretty():
292292
q0 = cirq.LineQubit(0)
293293
result = next(
294294
cirq.CliffordSimulator().simulate_moment_steps(cirq.Circuit(cirq.measure(q0, key='m')))
295295
)
296-
cirq.testing.assert_repr_pretty(result, "m=0\n" "|0⟩")
296+
cirq.testing.assert_repr_pretty(result, "m=0\n|0⟩")
297297
cirq.testing.assert_repr_pretty(result, "cirq.CliffordSimulatorStateResult(...)", cycle=True)
298298

299299

0 commit comments

Comments
 (0)