Skip to content

Commit 2635656

Browse files
authored
Switch to unquoted type annotations part 6 (#7325)
No change in the effective code. A batch of 50 files. Passes ruff check --target-version=py310 --select=UP037,TC001 Partially implements #1999
1 parent 575552a commit 2635656

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+296
-175
lines changed

cirq-aqt/cirq_aqt/aqt_device_test.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
from __future__ import annotations
16+
1517
from datetime import timedelta
1618
from typing import List
1719

@@ -38,7 +40,7 @@ def device(qubits) -> aqt_device.AQTDevice:
3840

3941

4042
class NotImplementedOperation(cirq.Operation):
41-
def with_qubits(self, *new_qubits) -> 'NotImplementedOperation':
43+
def with_qubits(self, *new_qubits) -> NotImplementedOperation:
4244
raise NotImplementedError()
4345

4446
@property

cirq-core/cirq/_compat_test.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14+
15+
from __future__ import annotations
16+
1417
import collections
1518
import dataclasses
1619
import importlib.metadata
@@ -635,7 +638,7 @@ def _type_repr_in_deprecated_module():
635638
] + _deprecation_origin
636639

637640

638-
def _trace_unhandled_exceptions(*args, queue: 'multiprocessing.Queue', func: Callable):
641+
def _trace_unhandled_exceptions(*args, queue: multiprocessing.Queue, func: Callable):
639642
try:
640643
func(*args)
641644
queue.put(None)

cirq-core/cirq/circuits/insert_strategy.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,18 @@
1414

1515
"""Hard-coded options for adding multiple operations to a circuit."""
1616

17+
from __future__ import annotations
18+
1719

1820
class InsertStrategy:
1921
"""Indicates preferences on how to add multiple operations to a circuit."""
2022

21-
NEW: 'InsertStrategy'
22-
NEW_THEN_INLINE: 'InsertStrategy'
23-
INLINE: 'InsertStrategy'
24-
EARLIEST: 'InsertStrategy'
23+
NEW: InsertStrategy
24+
NEW_THEN_INLINE: InsertStrategy
25+
INLINE: InsertStrategy
26+
EARLIEST: InsertStrategy
2527

26-
def __new__(cls, name: str, doc: str) -> 'InsertStrategy':
28+
def __new__(cls, name: str, doc: str) -> InsertStrategy:
2729
inst = getattr(cls, name, None)
2830
if not inst or not isinstance(inst, cls):
2931
inst = super().__new__(cls)

cirq-core/cirq/contrib/acquaintance/gates_test.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
from __future__ import annotations
16+
1517
from itertools import combinations, product
1618
from random import randint
1719
from string import ascii_lowercase as alphabet
@@ -257,7 +259,7 @@ def __init__(self, qubits: Sequence[cirq.Qid]) -> None:
257259
def qubits(self) -> Tuple[cirq.Qid, ...]:
258260
return self._qubits
259261

260-
def with_qubits(self, *new_qubits: cirq.Qid) -> 'OtherOperation':
262+
def with_qubits(self, *new_qubits: cirq.Qid) -> OtherOperation:
261263
return type(self)(self._qubits)
262264

263265
def __eq__(self, other):

cirq-core/cirq/contrib/graph_device/hypergraph.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
from __future__ import annotations
16+
1517
import itertools
1618
import random
1719
from typing import Any, Dict, FrozenSet, Hashable, Iterable, Mapping, Optional, Set, Tuple, Union
@@ -103,7 +105,7 @@ def __add__(self, other):
103105
@classmethod
104106
def random(
105107
cls, vertices: Union[int, Iterable], edge_probs: Mapping[int, float]
106-
) -> 'UndirectedHypergraph':
108+
) -> UndirectedHypergraph:
107109
"""A random hypergraph.
108110
109111
Every possible edge is included with probability edge_prob[len(edge)].

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,25 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14+
1415
"""Tools for measuring expectation values of Pauli strings with readout error mitigation."""
16+
17+
from __future__ import annotations
18+
1519
import itertools
1620
import time
17-
from typing import cast, Dict, FrozenSet, List, Optional, Sequence, Tuple, Union
21+
from typing import cast, Dict, FrozenSet, List, Optional, Sequence, Tuple, TYPE_CHECKING, Union
1822

1923
import attrs
2024
import numpy as np
2125

2226
from cirq import circuits, ops, work
2327
from cirq.contrib.shuffle_circuits import run_shuffled_with_readout_benchmarking
24-
from cirq.experiments import SingleQubitReadoutCalibrationResult
2528
from cirq.experiments.readout_confusion_matrix import TensoredConfusionMatrices
26-
from cirq.study import ResultDict
29+
30+
if TYPE_CHECKING:
31+
from cirq.experiments import SingleQubitReadoutCalibrationResult
32+
from cirq.study import ResultDict
2733

2834

2935
@attrs.frozen

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
from __future__ import annotations
16+
1517
import itertools
1618
import random
1719
from typing import Dict, Sequence

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
from __future__ import annotations
16+
1517
import networkx
1618

1719
from cirq import circuits, linalg

cirq-core/cirq/contrib/qasm_import/qasm.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
from __future__ import annotations
16+
1517
from cirq import circuits
1618
from cirq.contrib.qasm_import._parser import QasmParser
1719

cirq-core/cirq/contrib/quimb/density_matrix.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
# pylint: disable=wrong-or-nonexistent-copyright-notice
2+
3+
from __future__ import annotations
4+
25
from functools import lru_cache
36
from typing import Dict, List, Optional, Sequence, Tuple, Union
47

@@ -77,7 +80,7 @@ def _add_to_positions(
7780

7881
def circuit_to_density_matrix_tensors(
7982
circuit: cirq.Circuit, qubits: Optional[Sequence[cirq.Qid]] = None
80-
) -> Tuple[List[qtn.Tensor], Dict['cirq.Qid', int], Dict[Tuple[str, str], Tuple[float, float]]]:
83+
) -> Tuple[List[qtn.Tensor], Dict[cirq.Qid, int], Dict[Tuple[str, str], Tuple[float, float]]]:
8184
"""Given a circuit with mixtures or channels, construct a tensor network
8285
representation of the density matrix.
8386

0 commit comments

Comments
 (0)