Skip to content

Commit 7a0a7be

Browse files
authored
ruff - check and fix escape-sequence-in-docstring (#7670)
- ruff - activate D301 - escape-sequence-in-docstring - Fix escape sequences in docstrings, e.g., switch to raw docstrings when we need literal backslash. Partially implements #7505
1 parent c8d8d59 commit 7a0a7be

File tree

6 files changed

+11
-10
lines changed

6 files changed

+11
-10
lines changed

cirq-core/cirq/devices/grid_qubit.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ def rect(rows: int, cols: int, top: int = 0, left: int = 0, *, dimension: int) -
285285

286286
@staticmethod
287287
def from_diagram(diagram: str, dimension: int) -> list[GridQid]:
288-
"""Parse ASCII art device layout into a device.
288+
r"""Parse ASCII art device layout into a device.
289289
290290
As an example, the below diagram will create a list of GridQid in a
291291
pyramid structure.
@@ -322,7 +322,7 @@ def from_diagram(diagram: str, dimension: int) -> list[GridQid]:
322322
a row. Alphanumeric characters are assigned as qid.
323323
Dots ('.'), dashes ('-'), and spaces (' ') are treated as
324324
empty locations in the grid. If diagram has characters other
325-
than alphanumerics, spacers, and newlines ('\\n'), an error will
325+
than alphanumerics, spacers, and newlines ('\n'), an error will
326326
be thrown. The top-left corner of the diagram will be have
327327
coordinate (0, 0).
328328
@@ -439,7 +439,7 @@ def rect(rows: int, cols: int, top: int = 0, left: int = 0) -> list[GridQubit]:
439439

440440
@staticmethod
441441
def from_diagram(diagram: str) -> list[GridQubit]:
442-
"""Parse ASCII art into device layout info.
442+
r"""Parse ASCII art into device layout info.
443443
444444
As an example, the below diagram will create a list of
445445
GridQubit in a pyramid structure.
@@ -476,7 +476,7 @@ def from_diagram(diagram: str) -> list[GridQubit]:
476476
a row. Alphanumeric characters are assigned as qid.
477477
Dots ('.'), dashes ('-'), and spaces (' ') are treated as
478478
empty locations in the grid. If diagram has characters other
479-
than alphanumerics, spacers, and newlines ('\\n'), an error will
479+
than alphanumerics, spacers, and newlines ('\n'), an error will
480480
be thrown. The top-left corner of the diagram will be have
481481
coordinate (0,0).
482482
@@ -503,7 +503,7 @@ def _json_dict_(self) -> dict[str, Any]:
503503

504504

505505
def _ascii_diagram_to_coords(diagram: str) -> list[tuple[int, int]]:
506-
"""Parse ASCII art device layout into info about qids coordinates
506+
r"""Parse ASCII art device layout into info about qids coordinates
507507
508508
Args:
509509
diagram: String representing the qid layout. Each line represents

cirq-core/cirq/linalg/decompositions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ def so4_to_magic_su2s(
243243

244244
@value.value_equality(approximate=True)
245245
class AxisAngleDecomposition:
246-
"""Represents a unitary operation as an axis, angle, and global phase.
246+
r"""Represents a unitary operation as an axis, angle, and global phase.
247247
248248
The unitary $U$ is decomposed as follows:
249249

cirq-core/cirq/ops/named_qubit.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ def __str__(self) -> str:
148148

149149
@staticmethod
150150
def range(*args, prefix: str, dimension: int) -> list[NamedQid]:
151-
"""Returns a range of ``NamedQid``\\s.
151+
"""Returns a range of ``NamedQid``s.
152152
153153
The range returned starts with the prefix, and followed by a qid for
154154
each number in the range, e.g.:
@@ -166,7 +166,7 @@ def range(*args, prefix: str, dimension: int) -> list[NamedQid]:
166166
dimension: The dimension of the qid's Hilbert space, i.e.
167167
the number of quantum levels.
168168
Returns:
169-
A list of ``NamedQid``\\s.
169+
A list of ``NamedQid``s.
170170
"""
171171
return [NamedQid(f"{prefix}{i}", dimension=dimension) for i in range(*args)]
172172

cirq-core/cirq/vis/density_matrix.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def plot_density_matrix(
8484
show_text: bool = False,
8585
title: str | None = None,
8686
) -> plt.Axes:
87-
"""Generates a plot for a given density matrix.
87+
r"""Generates a plot for a given density matrix.
8888
8989
1. Each entry of the density matrix, a complex number, is plotted as an
9090
Argand Diagram where the partially filled red circle represents the magnitude

examples/stabilizer_code.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ def correct(self, qubits: list[cirq.Qid], ancillas: list[cirq.Qid]) -> cirq.Circ
322322
return circuit
323323

324324
def decode(self, qubits: list[cirq.Qid], ancillas: list[cirq.Qid], state_vector) -> list[int]:
325-
"""Computes the output of the circuit by projecting onto the \bar{Z}.
325+
r"""Computes the output of the circuit by projecting onto the \bar{Z}.
326326
327327
Args:
328328
qubits: the qubits where the (now corrected) code words are stored.

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ select = [
7474
# pylint expression-not-assigned, pointless-exception-statement,
7575
# pointless-statement, pointless-string-statement
7676
"B033", # duplicate-value, pylint duplicate-value
77+
"D301", # escape-sequence-in-docstring
7778
"D419", # empty-docstring, pylint empty-docstring
7879
"E402", # module-import-not-at-top-of-file, pylint wrong-import-position
7980
"E501", # line-too-long, pylint line-too-long

0 commit comments

Comments
 (0)