Skip to content

Commit fd95547

Browse files
authored
Replace type_workarounds.NotImplementedType with types.NotImplementedType (#6790)
- Replaced type_workarounds.NotImplementedType with types.NotImplementedType, removing the need for the type_workarounds module. - This change simplifies the codebase by relying on standard types, allowing us to delete the now-redundant type_workarounds.py file. Fixes #6775
1 parent d1b0430 commit fd95547

40 files changed

+48
-73
lines changed

cirq-core/cirq/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
# Low level
2727
_version,
2828
_doc,
29-
type_workarounds,
3029
)
3130

3231
with _import.delay_import('cirq.protocols'):

cirq-core/cirq/circuits/circuit.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import itertools
2626
import math
2727
from collections import defaultdict
28+
from types import NotImplementedType
2829
from typing import (
2930
AbstractSet,
3031
Any,
@@ -62,7 +63,6 @@
6263
from cirq.circuits.qasm_output import QasmOutput
6364
from cirq.circuits.text_diagram_drawer import TextDiagramDrawer
6465
from cirq.protocols import circuit_diagram_info_protocol
65-
from cirq.type_workarounds import NotImplementedType
6666

6767
if TYPE_CHECKING:
6868
import cirq

cirq-core/cirq/circuits/frozen_circuit.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# limitations under the License.
1414
"""An immutable version of the Circuit data structure."""
1515
from functools import cached_property
16+
from types import NotImplementedType
1617
from typing import (
1718
AbstractSet,
1819
FrozenSet,
@@ -30,7 +31,6 @@
3031
from cirq import protocols, _compat
3132
from cirq.circuits import AbstractCircuit, Alignment, Circuit
3233
from cirq.circuits.insert_strategy import InsertStrategy
33-
from cirq.type_workarounds import NotImplementedType
3434

3535
if TYPE_CHECKING:
3636
import cirq

cirq-core/cirq/circuits/moment.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"""A simplified time-slice of operations within a sequenced circuit."""
1616

1717
import itertools
18+
from types import NotImplementedType
1819
from typing import (
1920
AbstractSet,
2021
Any,
@@ -33,6 +34,7 @@
3334
TYPE_CHECKING,
3435
Union,
3536
)
37+
3638
from typing_extensions import Self
3739

3840
import numpy as np
@@ -41,7 +43,6 @@
4143
from cirq._import import LazyLoader
4244
from cirq.ops import raw_types, op_tree
4345
from cirq.protocols import circuit_diagram_info_protocol
44-
from cirq.type_workarounds import NotImplementedType
4546

4647
if TYPE_CHECKING:
4748
import cirq

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# limitations under the License.
1414

1515
import abc
16+
from types import NotImplementedType
1617
from typing import (
1718
Any,
1819
cast,
@@ -28,7 +29,6 @@
2829
)
2930

3031
from cirq import circuits, ops, protocols, transformers, value
31-
from cirq.type_workarounds import NotImplementedType
3232

3333
if TYPE_CHECKING:
3434
import cirq

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

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

15+
from types import NotImplementedType
1516
from typing import List, Union, Type, cast, TYPE_CHECKING
1617
from enum import Enum
18+
1719
import numpy as np
1820

1921
from cirq import ops, transformers, protocols, linalg
20-
from cirq.type_workarounds import NotImplementedType
2122

2223
if TYPE_CHECKING:
2324
import cirq

cirq-core/cirq/ops/clifford_gate.py

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

15-
from typing import Any, Dict, List, Optional, Sequence, Tuple, TYPE_CHECKING, Union
16-
1715
import functools
1816
from dataclasses import dataclass
17+
from types import NotImplementedType
18+
from typing import Any, Dict, List, Optional, Sequence, Tuple, TYPE_CHECKING, Union
19+
1920
import numpy as np
2021

2122
from cirq import protocols, value, linalg, qis
2223
from cirq._import import LazyLoader
2324
from cirq._compat import cached_method
2425
from cirq.ops import common_gates, named_qubit, raw_types, pauli_gates, phased_x_z_gate
2526
from cirq.ops.pauli_gates import Pauli
26-
from cirq.type_workarounds import NotImplementedType
2727

2828
if TYPE_CHECKING:
2929
import cirq

cirq-core/cirq/ops/common_gates.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
raised to a power (i.e. cirq.H**0.5). See the definition in EigenGate.
2626
"""
2727

28+
from types import NotImplementedType
2829
from typing import (
2930
Any,
3031
cast,
@@ -46,9 +47,6 @@
4647
from cirq._compat import proper_repr
4748
from cirq._doc import document
4849
from cirq.ops import controlled_gate, eigen_gate, gate_features, raw_types, control_values as cv
49-
50-
from cirq.type_workarounds import NotImplementedType
51-
5250
from cirq.ops.swap_gates import ISWAP, SWAP, ISwapPowGate, SwapPowGate
5351
from cirq.ops.measurement_gate import MeasurementGate
5452

cirq-core/cirq/ops/controlled_gate.py

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

15+
from types import NotImplementedType
1516
from typing import (
1617
AbstractSet,
1718
Any,
@@ -35,7 +36,6 @@
3536
matrix_gates,
3637
control_values as cv,
3738
)
38-
from cirq.type_workarounds import NotImplementedType
3939

4040
if TYPE_CHECKING:
4141
import cirq
@@ -255,7 +255,7 @@ def _unitary_(self) -> Union[np.ndarray, NotImplementedType]:
255255
def _has_mixture_(self) -> bool:
256256
return protocols.has_mixture(self.sub_gate)
257257

258-
def _mixture_(self) -> Union[np.ndarray, NotImplementedType]:
258+
def _mixture_(self) -> Union[Sequence[tuple[float, np.ndarray]], NotImplementedType]:
259259
qubits = line_qubit.LineQid.for_gate(self)
260260
op = self.sub_gate.on(*qubits[self.num_controls() :])
261261
c_op = cop.ControlledOperation(qubits[: self.num_controls()], op, self.control_values)

cirq-core/cirq/ops/controlled_gate_test.py

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

15+
from types import NotImplementedType
1516
from typing import Union, Tuple, cast
1617

1718
import numpy as np
1819
import pytest
1920
import sympy
2021

2122
import cirq
22-
from cirq.type_workarounds import NotImplementedType
2323

2424

2525
class GateUsingWorkspaceForApplyUnitary(cirq.testing.SingleQubitGate):

cirq-core/cirq/ops/controlled_operation.py

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

15+
from types import NotImplementedType
1516
from typing import (
1617
AbstractSet,
1718
Any,
@@ -38,7 +39,6 @@
3839
raw_types,
3940
control_values as cv,
4041
)
41-
from cirq.type_workarounds import NotImplementedType
4242

4343
if TYPE_CHECKING:
4444
import cirq

cirq-core/cirq/ops/controlled_operation_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import itertools
1616
import re
17+
from types import NotImplementedType
1718
from typing import cast, Tuple, Union
1819

1920
import numpy as np
@@ -22,7 +23,6 @@
2223

2324
import cirq
2425
from cirq import protocols
25-
from cirq.type_workarounds import NotImplementedType
2626

2727

2828
class GateUsingWorkspaceForApplyUnitary(cirq.testing.SingleQubitGate):

cirq-core/cirq/ops/dense_pauli_string.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import abc
1616
import numbers
17+
from types import NotImplementedType
1718
from typing import (
1819
AbstractSet,
1920
Any,
@@ -38,7 +39,6 @@
3839
from cirq import protocols, linalg, value
3940
from cirq._compat import proper_repr
4041
from cirq.ops import raw_types, identity, pauli_gates, global_phase_op, pauli_string
41-
from cirq.type_workarounds import NotImplementedType
4242

4343
if TYPE_CHECKING:
4444
import cirq

cirq-core/cirq/ops/eigen_gate.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import fractions
1616
import math
1717
import numbers
18+
from types import NotImplementedType
1819
from typing import (
1920
AbstractSet,
2021
Any,
@@ -35,7 +36,6 @@
3536
from cirq import value, protocols
3637
from cirq.linalg import tolerance
3738
from cirq.ops import raw_types
38-
from cirq.type_workarounds import NotImplementedType
3939

4040
if TYPE_CHECKING:
4141
import cirq

cirq-core/cirq/ops/gate_operation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import re
1818
import warnings
19+
from types import NotImplementedType
1920
from typing import (
2021
AbstractSet,
2122
Any,
@@ -38,7 +39,6 @@
3839

3940
from cirq import ops, protocols, value
4041
from cirq.ops import raw_types, gate_features, control_values as cv
41-
from cirq.type_workarounds import NotImplementedType
4242

4343
if TYPE_CHECKING:
4444
import cirq

cirq-core/cirq/ops/global_phase_op.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# limitations under the License.
1414
"""A no-qubit global phase operation."""
1515

16+
from types import NotImplementedType
1617
from typing import AbstractSet, Any, cast, Dict, Sequence, Tuple, Union, Optional, Collection
1718

1819
import numpy as np
@@ -21,7 +22,6 @@
2122
import cirq
2223
from cirq import value, protocols
2324
from cirq.ops import raw_types, controlled_gate, control_values as cv
24-
from cirq.type_workarounds import NotImplementedType
2525

2626

2727
@value.value_equality(approximate=True)

cirq-core/cirq/ops/identity.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@
1313
# limitations under the License.
1414
"""IdentityGate."""
1515

16+
from types import NotImplementedType
1617
from typing import Any, Dict, Optional, Tuple, TYPE_CHECKING, Sequence, Union
1718

1819
import numpy as np
1920
import sympy
2021

2122
from cirq import protocols, value
2223
from cirq._doc import document
23-
from cirq.type_workarounds import NotImplementedType
2424
from cirq.ops import raw_types
2525

2626
if TYPE_CHECKING:

cirq-core/cirq/ops/parallel_gate.py

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

15-
15+
from types import NotImplementedType
1616
from typing import AbstractSet, Union, Any, Optional, Tuple, TYPE_CHECKING, Dict
1717

1818
import numpy as np
1919

2020
from cirq import protocols, value
2121
from cirq.ops import raw_types
22-
from cirq.type_workarounds import NotImplementedType
2322

2423
if TYPE_CHECKING:
2524
import cirq

cirq-core/cirq/ops/pauli_gates.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414
import abc
15+
from types import NotImplementedType
1516
from typing import Any, cast, Tuple, TYPE_CHECKING, Union, Dict
1617

1718
from cirq._doc import document
1819
from cirq._import import LazyLoader
1920
from cirq.ops import common_gates, raw_types, identity
20-
from cirq.type_workarounds import NotImplementedType
2121

2222

2323
if TYPE_CHECKING:

cirq-core/cirq/ops/pauli_string.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import cmath
1515
import math
1616
import numbers
17+
from types import NotImplementedType
1718
from typing import (
1819
Any,
1920
cast,
@@ -56,7 +57,6 @@
5657
pauli_interaction_gate,
5758
raw_types,
5859
)
59-
from cirq.type_workarounds import NotImplementedType
6060

6161
if TYPE_CHECKING:
6262
import cirq

cirq-core/cirq/ops/phased_x_gate.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,20 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414
"""An `XPowGate` conjugated by `ZPowGate`s."""
15+
16+
from types import NotImplementedType
1517
from typing import AbstractSet, Any, cast, Dict, Optional, Sequence, Tuple, Union
1618

1719
import math
1820
import numbers
21+
1922
import numpy as np
2023
import sympy
2124

2225
import cirq
2326
from cirq import value, protocols
2427
from cirq._compat import proper_repr
2528
from cirq.ops import common_gates, raw_types
26-
from cirq.type_workarounds import NotImplementedType
2729

2830

2931
@value.value_equality(manual_cls=True, approximate=True)
@@ -130,7 +132,7 @@ def _trace_distance_bound_(self) -> Optional[float]:
130132
def _has_unitary_(self):
131133
return not self._is_parameterized_()
132134

133-
def _unitary_(self) -> Union[np.ndarray, NotImplementedType]:
135+
def _unitary_(self) -> Optional[Union[np.ndarray, NotImplementedType]]:
134136
"""See `cirq.SupportsUnitary`."""
135137
if self._is_parameterized_():
136138
return None

cirq-core/cirq/ops/raw_types.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import abc
1818
import functools
19+
from types import NotImplementedType
1920
from typing import (
2021
cast,
2122
AbstractSet,
@@ -42,7 +43,6 @@
4243
from cirq import protocols, value
4344
from cirq._import import LazyLoader
4445
from cirq._compat import __cirq_debug__, _method_cache_name, cached_method
45-
from cirq.type_workarounds import NotImplementedType
4646
from cirq.ops import control_values as cv
4747

4848
# Lazy imports to break circular dependencies.
@@ -879,7 +879,7 @@ def _mixture_(self) -> Sequence[Tuple[float, Any]]:
879879
def _has_kraus_(self) -> bool:
880880
return protocols.has_kraus(self.sub_operation)
881881

882-
def _kraus_(self) -> Union[Tuple[np.ndarray], NotImplementedType]:
882+
def _kraus_(self) -> Union[Tuple[np.ndarray, ...], NotImplementedType]:
883883
return protocols.kraus(self.sub_operation, NotImplemented)
884884

885885
@cached_method

0 commit comments

Comments
 (0)