From 39c4af2c719a05209fa4e01f477cf8c1a28d655b Mon Sep 17 00:00:00 2001 From: Pavol Juhas Date: Mon, 21 Nov 2022 17:41:47 -0800 Subject: [PATCH 1/2] Add missing comma after f-string-without-interpolation Remove obsolete checks `mixed-indentation` and `relative-import` specific to Python 2. Resolve pylint 2.15 complaints about these. --- dev_tools/conf/.pylintrc | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/dev_tools/conf/.pylintrc b/dev_tools/conf/.pylintrc index 084d1b1d0e2..bfec12fe0e5 100644 --- a/dev_tools/conf/.pylintrc +++ b/dev_tools/conf/.pylintrc @@ -20,7 +20,7 @@ enable= docstyle, duplicate-argument-name, expression-not-assigned, - f-string-without-interpolation + f-string-without-interpolation, function-redefined, inconsistent-mro, init-is-generator, @@ -29,14 +29,12 @@ enable= missing-kwoa, missing-param-doc, missing-raises-doc, - mixed-indentation, mixed-line-endings, no-value-for-parameter, nonexistent-operator, not-in-loop, pointless-statement, redefined-builtin, - relative-import, return-arg-in-generator, return-in-init, return-outside-function, From c6eed78eb8f62c4583af6d35d4bedac1b1ab9ca6 Mon Sep 17 00:00:00 2001 From: Pavol Juhas Date: Mon, 21 Nov 2022 18:16:09 -0800 Subject: [PATCH 2/2] Clean redundant f-strings that show for fixed pylintrc --- .../cirq/circuits/circuit_operation_test.py | 16 ++++++++-------- .../experiments/readout_confusion_matrix.py | 2 +- cirq-core/cirq/qis/clifford_tableau.py | 18 +++++++++--------- cirq-core/cirq/testing/circuit_compare.py | 2 +- cirq-core/cirq/testing/routing_devices_test.py | 2 +- .../cirq_google/engine/engine_validator.py | 2 +- cirq-google/cirq_google/engine/qcs_notebook.py | 2 +- 7 files changed, 22 insertions(+), 22 deletions(-) diff --git a/cirq-core/cirq/circuits/circuit_operation_test.py b/cirq-core/cirq/circuits/circuit_operation_test.py index 75a2791d688..e1710546e98 100644 --- a/cirq-core/cirq/circuits/circuit_operation_test.py +++ b/cirq-core/cirq/circuits/circuit_operation_test.py @@ -541,7 +541,7 @@ def test_string_format(): fc0 = cirq.FrozenCircuit() op0 = cirq.CircuitOperation(fc0) - assert str(op0) == f"[ ]" + assert str(op0) == "[ ]" fc0_global_phase_inner = cirq.FrozenCircuit( cirq.global_phase_operation(1j), cirq.global_phase_operation(1j) @@ -553,7 +553,7 @@ def test_string_format(): op0_global_phase_outer = cirq.CircuitOperation(fc0_global_phase_outer) assert ( str(op0_global_phase_outer) - == f"""\ + == """\ [ ] [ ] [ global phase: -0.5π ]""" @@ -563,7 +563,7 @@ def test_string_format(): op1 = cirq.CircuitOperation(fc1) assert ( str(op1) - == f"""\ + == """\ [ 0: ───X───────M('m')─── ] [ │ ] [ 1: ───H───@───M──────── ] @@ -599,10 +599,10 @@ def test_string_format(): ) assert ( str(op2) - == f"""\ + == """\ [ 0: ───X───X─── ] [ │ ] -[ 1: ───H───@─── ](qubit_map={{q(1): q(2)}}, parent_path=('outer', 'inner'),\ +[ 1: ───H───@─── ](qubit_map={q(1): q(2)}, parent_path=('outer', 'inner'),\ repetition_ids=['a', 'b', 'c'])""" ) assert ( @@ -635,9 +635,9 @@ def test_string_format(): indented_fc3_repr = repr(fc3).replace('\n', '\n ') assert ( str(op3) - == f"""\ -[ 0: ───X^b───M('m')─── ](qubit_map={{q(0): q(1)}}, \ -key_map={{m: p}}, params={{b: 2}})""" + == """\ +[ 0: ───X^b───M('m')─── ](qubit_map={q(0): q(1)}, \ +key_map={m: p}, params={b: 2})""" ) assert ( repr(op3) diff --git a/cirq-core/cirq/experiments/readout_confusion_matrix.py b/cirq-core/cirq/experiments/readout_confusion_matrix.py index ea0f96d569f..4fdc3c525ae 100644 --- a/cirq-core/cirq/experiments/readout_confusion_matrix.py +++ b/cirq-core/cirq/experiments/readout_confusion_matrix.py @@ -85,7 +85,7 @@ def __init__( pattern. """ if len(measure_qubits) == 0: - raise ValueError(f"measure_qubits cannot be empty.") + raise ValueError("measure_qubits cannot be empty.") if isinstance(confusion_matrices, np.ndarray): confusion_matrices = [confusion_matrices] measure_qubits = cast( diff --git a/cirq-core/cirq/qis/clifford_tableau.py b/cirq-core/cirq/qis/clifford_tableau.py index 460f260a613..bd73daccf76 100644 --- a/cirq-core/cirq/qis/clifford_tableau.py +++ b/cirq-core/cirq/qis/clifford_tableau.py @@ -174,9 +174,9 @@ def _reconstruct_rs(self, rs: Optional[np.ndarray]) -> np.ndarray: new_rs = np.append(rs, np.zeros(1, dtype=bool)) else: raise ValueError( - f"The value you passed for rs is not the correct shape and/or type. " - f"Please confirm that it's a single row with 2*num_qubits columns " - f"and of type bool." + "The value you passed for rs is not the correct shape and/or type. " + "Please confirm that it's a single row with 2*num_qubits columns " + "and of type bool." ) return new_rs @@ -196,9 +196,9 @@ def _reconstruct_xs(self, xs: Optional[np.ndarray]) -> np.ndarray: new_xs = np.append(xs, np.zeros((1, self.n), dtype=bool), axis=0) else: raise ValueError( - f"The value you passed for xs is not the correct shape and/or type. " - f"Please confirm that it's 2*num_qubits rows, num_qubits columns, " - f"and of type bool." + "The value you passed for xs is not the correct shape and/or type. " + "Please confirm that it's 2*num_qubits rows, num_qubits columns, " + "and of type bool." ) return new_xs @@ -219,9 +219,9 @@ def _reconstruct_zs(self, zs: Optional[np.ndarray]) -> np.ndarray: new_zs = np.append(zs, np.zeros((1, self.n), dtype=bool), axis=0) else: raise ValueError( - f"The value you passed for zs is not the correct shape and/or type. " - f"Please confirm that it's 2*num_qubits rows, num_qubits columns, " - f"and of type bool." + "The value you passed for zs is not the correct shape and/or type. " + "Please confirm that it's 2*num_qubits rows, num_qubits columns, " + "and of type bool." ) return new_zs diff --git a/cirq-core/cirq/testing/circuit_compare.py b/cirq-core/cirq/testing/circuit_compare.py index 4b96a9fb61a..a6047c75eab 100644 --- a/cirq-core/cirq/testing/circuit_compare.py +++ b/cirq-core/cirq/testing/circuit_compare.py @@ -241,7 +241,7 @@ def assert_circuits_have_same_unitary_given_final_permutation( if not set(qubit_map.keys()).issubset(actual.all_qubits()): raise ValueError( - f"'qubit_map' must be a mapping of the qubits in the circuit 'actual' to themselves." + "'qubit_map' must be a mapping of the qubits in the circuit 'actual' to themselves." ) actual_cp = actual.unfreeze() diff --git a/cirq-core/cirq/testing/routing_devices_test.py b/cirq-core/cirq/testing/routing_devices_test.py index 5369b0fc20c..814808b84dc 100644 --- a/cirq-core/cirq/testing/routing_devices_test.py +++ b/cirq-core/cirq/testing/routing_devices_test.py @@ -99,7 +99,7 @@ def test_allowed_multi_qubit_gates(): device.validate_operation(cirq.MeasurementGate(2).on(*cirq.LineQubit.range(2))) device.validate_operation(cirq.MeasurementGate(3).on(*cirq.LineQubit.range(3))) - with pytest.raises(ValueError, match=f"Unsupported operation"): + with pytest.raises(ValueError, match="Unsupported operation"): device.validate_operation(cirq.CCNOT(*cirq.LineQubit.range(3))) device.validate_operation(cirq.CNOT(*cirq.LineQubit.range(2))) diff --git a/cirq-google/cirq_google/engine/engine_validator.py b/cirq-google/cirq_google/engine/engine_validator.py index 483e71b1afc..6d0ace5f2cf 100644 --- a/cirq-google/cirq_google/engine/engine_validator.py +++ b/cirq-google/cirq_google/engine/engine_validator.py @@ -51,7 +51,7 @@ def _verify_reps( total_reps += len(list(cirq.to_resolvers(sweep))) * repetitions if total_reps > max_repetitions: raise RuntimeError( - f'No requested processors currently support the number of requested total repetitions.' + 'No requested processors currently support the number of requested total repetitions.' ) diff --git a/cirq-google/cirq_google/engine/qcs_notebook.py b/cirq-google/cirq_google/engine/qcs_notebook.py index 10549ba392a..73c5d85f78b 100644 --- a/cirq-google/cirq_google/engine/qcs_notebook.py +++ b/cirq-google/cirq_google/engine/qcs_notebook.py @@ -106,7 +106,7 @@ def get_qcs_objects_for_notebook( print("Authentication complete.") except Exception as exc: print(f"Authentication failed: {exc}") - print(f"Using virtual engine instead.") + print("Using virtual engine instead.") virtual = True if not virtual: