|
29 | 29 | AbstractSet, |
30 | 30 | Any, |
31 | 31 | Callable, |
32 | | - Mapping, |
33 | | - MutableSequence, |
34 | 32 | cast, |
35 | 33 | Dict, |
36 | 34 | FrozenSet, |
37 | 35 | Iterable, |
38 | 36 | Iterator, |
39 | 37 | List, |
| 38 | + Mapping, |
| 39 | + MutableSequence, |
40 | 40 | Optional, |
41 | 41 | overload, |
42 | 42 | Sequence, |
|
58 | 58 | from cirq.circuits._bucket_priority_queue import BucketPriorityQueue |
59 | 59 | from cirq.circuits.circuit_operation import CircuitOperation |
60 | 60 | from cirq.circuits.insert_strategy import InsertStrategy |
| 61 | +from cirq.circuits.moment import Moment |
61 | 62 | from cirq.circuits.qasm_output import QasmOutput |
62 | 63 | from cirq.circuits.text_diagram_drawer import TextDiagramDrawer |
63 | | -from cirq.circuits.moment import Moment |
64 | 64 | from cirq.protocols import circuit_diagram_info_protocol |
65 | 65 | from cirq.type_workarounds import NotImplementedType |
66 | 66 |
|
@@ -203,19 +203,24 @@ def unfreeze(self, copy: bool = True) -> 'cirq.Circuit': |
203 | 203 | copy: If True and 'self' is a Circuit, returns a copy that circuit. |
204 | 204 | """ |
205 | 205 |
|
206 | | - def __bool__(self): |
| 206 | + def __bool__(self) -> bool: |
207 | 207 | return bool(self.moments) |
208 | 208 |
|
209 | | - def __eq__(self, other): |
| 209 | + def __eq__(self, other) -> bool: |
210 | 210 | if not isinstance(other, AbstractCircuit): |
211 | 211 | return NotImplemented |
212 | | - return tuple(self.moments) == tuple(other.moments) |
| 212 | + return other is self or ( |
| 213 | + len(self.moments) == len(other.moments) |
| 214 | + and all(m0 == m1 for m0, m1 in zip(self.moments, other.moments)) |
| 215 | + ) |
213 | 216 |
|
214 | 217 | def _approx_eq_(self, other: Any, atol: Union[int, float]) -> bool: |
215 | 218 | """See `cirq.protocols.SupportsApproximateEquality`.""" |
216 | 219 | if not isinstance(other, AbstractCircuit): |
217 | 220 | return NotImplemented |
218 | | - return cirq.protocols.approx_eq(tuple(self.moments), tuple(other.moments), atol=atol) |
| 221 | + return other is self or cirq.protocols.approx_eq( |
| 222 | + tuple(self.moments), tuple(other.moments), atol=atol |
| 223 | + ) |
219 | 224 |
|
220 | 225 | def __ne__(self, other) -> bool: |
221 | 226 | return not self == other |
|
0 commit comments