Skip to content

Commit

Permalink
Use f-strings in the pr_monitor tool (#6208)
Browse files Browse the repository at this point in the history
* pr_monitor - convert to f-strings to satisfy pylint consider-using-f-string

* clean up some redundant fixed strings concatenations

* also pin pytest-cov==3 to unblock CI coverage check which failed
  because pytest-cov==4.1.0 does not see line hits in a subprocess.

Finalizes #6171
  • Loading branch information
pavoljuhas committed Jul 22, 2023
1 parent 6e562e6 commit 43d0372
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 92 deletions.
3 changes: 1 addition & 2 deletions cirq-core/cirq/_compat_test.py
Expand Up @@ -781,8 +781,7 @@ def test_deprecated_module_deadline_validation():

def _test_broken_module_1_inner():
with pytest.raises(
DeprecatedModuleImportError,
match="missing_module cannot be imported. " "The typical reasons",
DeprecatedModuleImportError, match="missing_module cannot be imported. The typical reasons"
):
# pylint: disable=unused-import
import cirq.testing._compat_test_data.broken_ref as br # type: ignore
Expand Down
2 changes: 1 addition & 1 deletion cirq-core/cirq/qis/measures.py
Expand Up @@ -211,7 +211,7 @@ def _numpy_arrays_to_state_vectors_or_density_matrices(
state2.shape[0] if state2.ndim == 2 else np.prod(state2.shape, dtype=np.int64).item()
)
if dim1 != dim2:
raise ValueError('Mismatched dimensions in given states: ' f'{dim1} and {dim2}.')
raise ValueError(f'Mismatched dimensions in given states: {dim1} and {dim2}.')
if qid_shape is None:
qid_shape = (dim1,)
else:
Expand Down
2 changes: 1 addition & 1 deletion cirq-core/cirq/qis/states.py
Expand Up @@ -314,7 +314,7 @@ def density_matrix(
ValueError: Invalid density matrix.
"""
if state.ndim != 2 or state.shape[0] != state.shape[1]:
raise ValueError('A density matrix must be a square matrix. ' f'Got shape {state.shape}.')
raise ValueError(f'A density matrix must be a square matrix. Got shape {state.shape}.')
dim, _ = state.shape
if qid_shape is None:
qid_shape = _infer_qid_shape_from_dimension(dim)
Expand Down
3 changes: 1 addition & 2 deletions cirq-google/cirq_google/calibration/engine_simulator.py
Expand Up @@ -482,7 +482,6 @@ def _convert_to_circuit_with_drift(
simulator: PhasedFSimEngineSimulator, circuit: cirq.AbstractCircuit
) -> cirq.Circuit:
def map_func(op: cirq.Operation, _) -> cirq.Operation:

if op.gate is None:
raise IncompatibleMomentError(f'Operation {op} has a missing gate')

Expand All @@ -495,7 +494,7 @@ def map_func(op: cirq.Operation, _) -> cirq.Operation:
translated = simulator.gates_translator(op.gate)
if translated is None:
raise IncompatibleMomentError(
f'Moment contains non-single qubit operation ' f'{op} with unsupported gate'
f'Moment contains non-single qubit operation {op} with unsupported gate'
)

a, b = op.qubits
Expand Down
2 changes: 1 addition & 1 deletion cirq-google/cirq_google/engine/engine_program.py
Expand Up @@ -550,7 +550,7 @@ def _deserialize_program(code: any_pb2.Any, program_num: Optional[int] = None) -
batch = v2.batch_pb2.BatchProgram.FromString(code.value)
if abs(program_num) >= len(batch.programs):
raise ValueError(
f'Only {len(batch.programs)} in the batch but ' f'index {program_num} was specified'
f'Only {len(batch.programs)} in the batch but index {program_num} was specified'
)

program = batch.programs[program_num]
Expand Down
2 changes: 1 addition & 1 deletion cirq-google/cirq_google/serialization/op_serializer.py
Expand Up @@ -134,7 +134,7 @@ def to_proto(
except KeyError as err:
# Circuits must be serialized prior to any CircuitOperations that use them.
raise ValueError(
'Encountered a circuit not in the constants table. ' f'Full error message:\n{err}'
f'Encountered a circuit not in the constants table. Full error message:\n{err}'
)

if (
Expand Down
2 changes: 1 addition & 1 deletion dev_tools/modules.py
Expand Up @@ -220,7 +220,7 @@ def _print_version():

def _add_print_version_cmd(subparsers):
print_version_cmd = subparsers.add_parser(
"print_version", help="Check that all module versions are the same, " "and print it."
"print_version", help="Check that all module versions are the same, and print it."
)
print_version_cmd.set_defaults(func=_print_version)

Expand Down

0 comments on commit 43d0372

Please sign in to comment.