Skip to content

Commit f5228d7

Browse files
authored
Finalize switch to PEP 585 style type annotations (#7367)
Clean up used of old-style type names in docstrings and notebooks. Remove unused imports and define necessary annotation types for doctest. Related to #7339
1 parent 513f309 commit f5228d7

File tree

18 files changed

+180
-190
lines changed

18 files changed

+180
-190
lines changed

cirq-core/cirq/circuits/circuit.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -918,7 +918,7 @@ def _has_op_at(self, moment_index: int, qubits: Iterable[cirq.Qid]) -> bool:
918918
def all_qubits(self) -> frozenset[cirq.Qid]:
919919
"""Returns the qubits acted upon by Operations in this circuit.
920920
921-
Returns: FrozenSet of `cirq.Qid` objects acted on by all operations
921+
Returns: frozenset of `cirq.Qid` objects acted on by all operations
922922
in this circuit.
923923
"""
924924
return frozenset(q for m in self.moments for q in m.qubits)
@@ -966,15 +966,15 @@ def all_measurement_key_objs(self) -> frozenset[cirq.MeasurementKey]:
966966
def _measurement_key_objs_(self) -> frozenset[cirq.MeasurementKey]:
967967
"""Returns the set of all measurement keys in this circuit.
968968
969-
Returns: FrozenSet of `cirq.MeasurementKey` objects that are
969+
Returns: frozenset of `cirq.MeasurementKey` objects that are
970970
in this circuit.
971971
"""
972972
return self.all_measurement_key_objs()
973973

974974
def all_measurement_key_names(self) -> frozenset[str]:
975975
"""Returns the set of all measurement key names in this circuit.
976976
977-
Returns: FrozenSet of strings that are the measurement key
977+
Returns: frozenset of strings that are the measurement key
978978
names in this circuit.
979979
"""
980980
return frozenset(

cirq-core/cirq/linalg/decompositions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def unitary_eig(
116116
was unitary.
117117
118118
Returns:
119-
A Tuple of
119+
A tuple of
120120
eigvals: The eigenvalues of `matrix`.
121121
V: The unitary matrix with the eigenvectors as columns.
122122

cirq-core/cirq/ops/arithmetic_operation.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,21 +44,21 @@ class ArithmeticGate(Gate, metaclass=abc.ABCMeta):
4444
>>> class Add(cirq.ArithmeticGate):
4545
... def __init__(
4646
... self,
47-
... target_register: '[int, Sequence[int]]',
48-
... input_register: 'Union[int, Sequence[int]]',
47+
... target_register: int | Sequence[int],
48+
... input_register: int | Sequence[int],
4949
... ):
5050
... self.target_register = target_register
5151
... self.input_register = input_register
5252
...
53-
... def registers(self) -> 'Sequence[Union[int, Sequence[int]]]':
53+
... def registers(self) -> Sequence[int | Sequence[int]]:
5454
... return self.target_register, self.input_register
5555
...
5656
... def with_registers(
57-
... self, *new_registers: 'Union[int, Sequence[int]]'
57+
... self, *new_registers: int | Sequence[int]
5858
... ) -> 'Add':
5959
... return Add(*new_registers)
6060
...
61-
... def apply(self, *register_values: int) -> 'Union[int, Iterable[int]]':
61+
... def apply(self, *register_values: int) -> int | Iterable[int]:
6262
... return sum(register_values)
6363
>>> cirq.unitary(
6464
... Add(target_register=[2, 2],

cirq-core/cirq/ops/op_tree.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
- A list of operations (a `list[cirq.Operation]`).
4141
- A list of lists of operations (a `list[list[cirq.Operation]]`).
4242
- A list mixing operations and generators of operations
43-
(a `list[Union[cirq.Operation, Iterator[cirq.Operation]]]`).
43+
(a `list[cirq.Operation | Iterator[cirq.Operation]]`).
4444
- Generally anything that can be iterated, and its items iterated, and
4545
so forth recursively until a bottom layer of operations is found.
4646
""",

cirq-core/cirq/ops/raw_types.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ def _default_shape_from_num_qubits(self) -> tuple[int, ...]:
449449

450450
@value.alternative(requires='_num_qubits_', implementation=_default_shape_from_num_qubits)
451451
def _qid_shape_(self) -> tuple[int, ...]:
452-
"""Returns a Tuple containing the number of quantum levels of each qid
452+
"""Returns a tuple containing the number of quantum levels of each qid
453453
the gate acts on. E.g. (2, 2, 2) for the three-qubit CCZ gate and
454454
(3, 3) for a 2-qutrit ternary gate.
455455
"""

0 commit comments

Comments
 (0)