From fd95547ac4962cfa3d0d1ff707a8de26ce148511 Mon Sep 17 00:00:00 2001 From: Festus Ayobami Owumi Date: Wed, 13 Nov 2024 09:01:18 +0100 Subject: [PATCH] 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 --- cirq-core/cirq/__init__.py | 1 - cirq-core/cirq/circuits/circuit.py | 2 +- cirq-core/cirq/circuits/frozen_circuit.py | 2 +- cirq-core/cirq/circuits/moment.py | 3 ++- .../cirq/contrib/acquaintance/permutation.py | 2 +- .../paulistring/clifford_target_gateset.py | 3 ++- cirq-core/cirq/ops/clifford_gate.py | 6 ++--- cirq-core/cirq/ops/common_gates.py | 4 +--- cirq-core/cirq/ops/controlled_gate.py | 4 ++-- cirq-core/cirq/ops/controlled_gate_test.py | 2 +- cirq-core/cirq/ops/controlled_operation.py | 2 +- .../cirq/ops/controlled_operation_test.py | 2 +- cirq-core/cirq/ops/dense_pauli_string.py | 2 +- cirq-core/cirq/ops/eigen_gate.py | 2 +- cirq-core/cirq/ops/gate_operation.py | 2 +- cirq-core/cirq/ops/global_phase_op.py | 2 +- cirq-core/cirq/ops/identity.py | 2 +- cirq-core/cirq/ops/parallel_gate.py | 3 +-- cirq-core/cirq/ops/pauli_gates.py | 2 +- cirq-core/cirq/ops/pauli_string.py | 2 +- cirq-core/cirq/ops/phased_x_gate.py | 6 +++-- cirq-core/cirq/ops/raw_types.py | 4 ++-- cirq-core/cirq/protocols/act_on_protocol.py | 2 +- .../cirq/protocols/apply_channel_protocol.py | 2 +- .../cirq/protocols/apply_mixture_protocol.py | 3 +-- .../cirq/protocols/apply_unitary_protocol.py | 2 +- cirq-core/cirq/protocols/commutes_protocol.py | 2 +- .../cirq/protocols/control_key_protocol.py | 2 +- .../cirq/protocols/decompose_protocol.py | 2 +- .../cirq/protocols/json_serialization.py | 2 +- cirq-core/cirq/protocols/kraus_protocol.py | 4 +--- .../protocols/measurement_key_protocol.py | 2 +- cirq-core/cirq/protocols/mixture_protocol.py | 3 ++- cirq-core/cirq/protocols/qasm.py | 2 +- .../cirq/protocols/qid_shape_protocol.py | 2 +- cirq-core/cirq/protocols/unitary_protocol.py | 2 +- .../clifford/stabilizer_simulation_state.py | 2 +- cirq-core/cirq/sim/simulation_state_base.py | 2 +- .../cirq/testing/consistent_protocols_test.py | 2 +- cirq-core/cirq/type_workarounds.py | 23 ------------------- 40 files changed, 48 insertions(+), 73 deletions(-) delete mode 100644 cirq-core/cirq/type_workarounds.py diff --git a/cirq-core/cirq/__init__.py b/cirq-core/cirq/__init__.py index 15a014d16f1..9293a7e7bfc 100644 --- a/cirq-core/cirq/__init__.py +++ b/cirq-core/cirq/__init__.py @@ -26,7 +26,6 @@ # Low level _version, _doc, - type_workarounds, ) with _import.delay_import('cirq.protocols'): diff --git a/cirq-core/cirq/circuits/circuit.py b/cirq-core/cirq/circuits/circuit.py index 24de6a0a5d4..3e0f10f8c6a 100644 --- a/cirq-core/cirq/circuits/circuit.py +++ b/cirq-core/cirq/circuits/circuit.py @@ -25,6 +25,7 @@ import itertools import math from collections import defaultdict +from types import NotImplementedType from typing import ( AbstractSet, Any, @@ -62,7 +63,6 @@ from cirq.circuits.qasm_output import QasmOutput from cirq.circuits.text_diagram_drawer import TextDiagramDrawer from cirq.protocols import circuit_diagram_info_protocol -from cirq.type_workarounds import NotImplementedType if TYPE_CHECKING: import cirq diff --git a/cirq-core/cirq/circuits/frozen_circuit.py b/cirq-core/cirq/circuits/frozen_circuit.py index 0781213d954..15bf107d900 100644 --- a/cirq-core/cirq/circuits/frozen_circuit.py +++ b/cirq-core/cirq/circuits/frozen_circuit.py @@ -13,6 +13,7 @@ # limitations under the License. """An immutable version of the Circuit data structure.""" from functools import cached_property +from types import NotImplementedType from typing import ( AbstractSet, FrozenSet, @@ -30,7 +31,6 @@ from cirq import protocols, _compat from cirq.circuits import AbstractCircuit, Alignment, Circuit from cirq.circuits.insert_strategy import InsertStrategy -from cirq.type_workarounds import NotImplementedType if TYPE_CHECKING: import cirq diff --git a/cirq-core/cirq/circuits/moment.py b/cirq-core/cirq/circuits/moment.py index 923adfbd0de..b64957eeb1e 100644 --- a/cirq-core/cirq/circuits/moment.py +++ b/cirq-core/cirq/circuits/moment.py @@ -15,6 +15,7 @@ """A simplified time-slice of operations within a sequenced circuit.""" import itertools +from types import NotImplementedType from typing import ( AbstractSet, Any, @@ -33,6 +34,7 @@ TYPE_CHECKING, Union, ) + from typing_extensions import Self import numpy as np @@ -41,7 +43,6 @@ from cirq._import import LazyLoader from cirq.ops import raw_types, op_tree from cirq.protocols import circuit_diagram_info_protocol -from cirq.type_workarounds import NotImplementedType if TYPE_CHECKING: import cirq diff --git a/cirq-core/cirq/contrib/acquaintance/permutation.py b/cirq-core/cirq/contrib/acquaintance/permutation.py index cae68eee1ef..383b3731690 100644 --- a/cirq-core/cirq/contrib/acquaintance/permutation.py +++ b/cirq-core/cirq/contrib/acquaintance/permutation.py @@ -13,6 +13,7 @@ # limitations under the License. import abc +from types import NotImplementedType from typing import ( Any, cast, @@ -28,7 +29,6 @@ ) from cirq import circuits, ops, protocols, transformers, value -from cirq.type_workarounds import NotImplementedType if TYPE_CHECKING: import cirq diff --git a/cirq-core/cirq/contrib/paulistring/clifford_target_gateset.py b/cirq-core/cirq/contrib/paulistring/clifford_target_gateset.py index ae555a0bc07..1b20f91d70c 100644 --- a/cirq-core/cirq/contrib/paulistring/clifford_target_gateset.py +++ b/cirq-core/cirq/contrib/paulistring/clifford_target_gateset.py @@ -12,12 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. +from types import NotImplementedType from typing import List, Union, Type, cast, TYPE_CHECKING from enum import Enum + import numpy as np from cirq import ops, transformers, protocols, linalg -from cirq.type_workarounds import NotImplementedType if TYPE_CHECKING: import cirq diff --git a/cirq-core/cirq/ops/clifford_gate.py b/cirq-core/cirq/ops/clifford_gate.py index 82ce7ebe42e..972c7a1b4c1 100644 --- a/cirq-core/cirq/ops/clifford_gate.py +++ b/cirq-core/cirq/ops/clifford_gate.py @@ -12,10 +12,11 @@ # See the License for the specific language governing permissions and # limitations under the License. -from typing import Any, Dict, List, Optional, Sequence, Tuple, TYPE_CHECKING, Union - import functools from dataclasses import dataclass +from types import NotImplementedType +from typing import Any, Dict, List, Optional, Sequence, Tuple, TYPE_CHECKING, Union + import numpy as np from cirq import protocols, value, linalg, qis @@ -23,7 +24,6 @@ from cirq._compat import cached_method from cirq.ops import common_gates, named_qubit, raw_types, pauli_gates, phased_x_z_gate from cirq.ops.pauli_gates import Pauli -from cirq.type_workarounds import NotImplementedType if TYPE_CHECKING: import cirq diff --git a/cirq-core/cirq/ops/common_gates.py b/cirq-core/cirq/ops/common_gates.py index af259c6d19b..fea2ac9996f 100644 --- a/cirq-core/cirq/ops/common_gates.py +++ b/cirq-core/cirq/ops/common_gates.py @@ -25,6 +25,7 @@ raised to a power (i.e. cirq.H**0.5). See the definition in EigenGate. """ +from types import NotImplementedType from typing import ( Any, cast, @@ -46,9 +47,6 @@ from cirq._compat import proper_repr from cirq._doc import document from cirq.ops import controlled_gate, eigen_gate, gate_features, raw_types, control_values as cv - -from cirq.type_workarounds import NotImplementedType - from cirq.ops.swap_gates import ISWAP, SWAP, ISwapPowGate, SwapPowGate from cirq.ops.measurement_gate import MeasurementGate diff --git a/cirq-core/cirq/ops/controlled_gate.py b/cirq-core/cirq/ops/controlled_gate.py index 641b52fb9ff..292c13dc3d2 100644 --- a/cirq-core/cirq/ops/controlled_gate.py +++ b/cirq-core/cirq/ops/controlled_gate.py @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +from types import NotImplementedType from typing import ( AbstractSet, Any, @@ -35,7 +36,6 @@ matrix_gates, control_values as cv, ) -from cirq.type_workarounds import NotImplementedType if TYPE_CHECKING: import cirq @@ -255,7 +255,7 @@ def _unitary_(self) -> Union[np.ndarray, NotImplementedType]: def _has_mixture_(self) -> bool: return protocols.has_mixture(self.sub_gate) - def _mixture_(self) -> Union[np.ndarray, NotImplementedType]: + def _mixture_(self) -> Union[Sequence[tuple[float, np.ndarray]], NotImplementedType]: qubits = line_qubit.LineQid.for_gate(self) op = self.sub_gate.on(*qubits[self.num_controls() :]) c_op = cop.ControlledOperation(qubits[: self.num_controls()], op, self.control_values) diff --git a/cirq-core/cirq/ops/controlled_gate_test.py b/cirq-core/cirq/ops/controlled_gate_test.py index b9e09c5a6e1..555c04bb850 100644 --- a/cirq-core/cirq/ops/controlled_gate_test.py +++ b/cirq-core/cirq/ops/controlled_gate_test.py @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +from types import NotImplementedType from typing import Union, Tuple, cast import numpy as np @@ -19,7 +20,6 @@ import sympy import cirq -from cirq.type_workarounds import NotImplementedType class GateUsingWorkspaceForApplyUnitary(cirq.testing.SingleQubitGate): diff --git a/cirq-core/cirq/ops/controlled_operation.py b/cirq-core/cirq/ops/controlled_operation.py index 85c61cb298d..dbcd3026327 100644 --- a/cirq-core/cirq/ops/controlled_operation.py +++ b/cirq-core/cirq/ops/controlled_operation.py @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +from types import NotImplementedType from typing import ( AbstractSet, Any, @@ -38,7 +39,6 @@ raw_types, control_values as cv, ) -from cirq.type_workarounds import NotImplementedType if TYPE_CHECKING: import cirq diff --git a/cirq-core/cirq/ops/controlled_operation_test.py b/cirq-core/cirq/ops/controlled_operation_test.py index 1f1cb3a2531..dc6f2a7ece4 100644 --- a/cirq-core/cirq/ops/controlled_operation_test.py +++ b/cirq-core/cirq/ops/controlled_operation_test.py @@ -14,6 +14,7 @@ import itertools import re +from types import NotImplementedType from typing import cast, Tuple, Union import numpy as np @@ -22,7 +23,6 @@ import cirq from cirq import protocols -from cirq.type_workarounds import NotImplementedType class GateUsingWorkspaceForApplyUnitary(cirq.testing.SingleQubitGate): diff --git a/cirq-core/cirq/ops/dense_pauli_string.py b/cirq-core/cirq/ops/dense_pauli_string.py index 9893b64f706..f5f07953f78 100644 --- a/cirq-core/cirq/ops/dense_pauli_string.py +++ b/cirq-core/cirq/ops/dense_pauli_string.py @@ -14,6 +14,7 @@ import abc import numbers +from types import NotImplementedType from typing import ( AbstractSet, Any, @@ -38,7 +39,6 @@ from cirq import protocols, linalg, value from cirq._compat import proper_repr from cirq.ops import raw_types, identity, pauli_gates, global_phase_op, pauli_string -from cirq.type_workarounds import NotImplementedType if TYPE_CHECKING: import cirq diff --git a/cirq-core/cirq/ops/eigen_gate.py b/cirq-core/cirq/ops/eigen_gate.py index f11637b4fd6..b9ffbed9702 100644 --- a/cirq-core/cirq/ops/eigen_gate.py +++ b/cirq-core/cirq/ops/eigen_gate.py @@ -15,6 +15,7 @@ import fractions import math import numbers +from types import NotImplementedType from typing import ( AbstractSet, Any, @@ -35,7 +36,6 @@ from cirq import value, protocols from cirq.linalg import tolerance from cirq.ops import raw_types -from cirq.type_workarounds import NotImplementedType if TYPE_CHECKING: import cirq diff --git a/cirq-core/cirq/ops/gate_operation.py b/cirq-core/cirq/ops/gate_operation.py index db5be010923..0101111a4cc 100644 --- a/cirq-core/cirq/ops/gate_operation.py +++ b/cirq-core/cirq/ops/gate_operation.py @@ -16,6 +16,7 @@ import re import warnings +from types import NotImplementedType from typing import ( AbstractSet, Any, @@ -38,7 +39,6 @@ from cirq import ops, protocols, value from cirq.ops import raw_types, gate_features, control_values as cv -from cirq.type_workarounds import NotImplementedType if TYPE_CHECKING: import cirq diff --git a/cirq-core/cirq/ops/global_phase_op.py b/cirq-core/cirq/ops/global_phase_op.py index 6a64a634aa6..5348c5632e3 100644 --- a/cirq-core/cirq/ops/global_phase_op.py +++ b/cirq-core/cirq/ops/global_phase_op.py @@ -13,6 +13,7 @@ # limitations under the License. """A no-qubit global phase operation.""" +from types import NotImplementedType from typing import AbstractSet, Any, cast, Dict, Sequence, Tuple, Union, Optional, Collection import numpy as np @@ -21,7 +22,6 @@ import cirq from cirq import value, protocols from cirq.ops import raw_types, controlled_gate, control_values as cv -from cirq.type_workarounds import NotImplementedType @value.value_equality(approximate=True) diff --git a/cirq-core/cirq/ops/identity.py b/cirq-core/cirq/ops/identity.py index 361e70c4ea7..46de3bea8fd 100644 --- a/cirq-core/cirq/ops/identity.py +++ b/cirq-core/cirq/ops/identity.py @@ -13,6 +13,7 @@ # limitations under the License. """IdentityGate.""" +from types import NotImplementedType from typing import Any, Dict, Optional, Tuple, TYPE_CHECKING, Sequence, Union import numpy as np @@ -20,7 +21,6 @@ from cirq import protocols, value from cirq._doc import document -from cirq.type_workarounds import NotImplementedType from cirq.ops import raw_types if TYPE_CHECKING: diff --git a/cirq-core/cirq/ops/parallel_gate.py b/cirq-core/cirq/ops/parallel_gate.py index 9fefa56289d..584d76d43ff 100644 --- a/cirq-core/cirq/ops/parallel_gate.py +++ b/cirq-core/cirq/ops/parallel_gate.py @@ -12,14 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. - +from types import NotImplementedType from typing import AbstractSet, Union, Any, Optional, Tuple, TYPE_CHECKING, Dict import numpy as np from cirq import protocols, value from cirq.ops import raw_types -from cirq.type_workarounds import NotImplementedType if TYPE_CHECKING: import cirq diff --git a/cirq-core/cirq/ops/pauli_gates.py b/cirq-core/cirq/ops/pauli_gates.py index a2132a6a4bb..e09e5ede009 100644 --- a/cirq-core/cirq/ops/pauli_gates.py +++ b/cirq-core/cirq/ops/pauli_gates.py @@ -12,12 +12,12 @@ # See the License for the specific language governing permissions and # limitations under the License. import abc +from types import NotImplementedType from typing import Any, cast, Tuple, TYPE_CHECKING, Union, Dict from cirq._doc import document from cirq._import import LazyLoader from cirq.ops import common_gates, raw_types, identity -from cirq.type_workarounds import NotImplementedType if TYPE_CHECKING: diff --git a/cirq-core/cirq/ops/pauli_string.py b/cirq-core/cirq/ops/pauli_string.py index 1978b6ba031..f8ad21015e6 100644 --- a/cirq-core/cirq/ops/pauli_string.py +++ b/cirq-core/cirq/ops/pauli_string.py @@ -14,6 +14,7 @@ import cmath import math import numbers +from types import NotImplementedType from typing import ( Any, cast, @@ -56,7 +57,6 @@ pauli_interaction_gate, raw_types, ) -from cirq.type_workarounds import NotImplementedType if TYPE_CHECKING: import cirq diff --git a/cirq-core/cirq/ops/phased_x_gate.py b/cirq-core/cirq/ops/phased_x_gate.py index 26548a64b47..4a1b6069268 100644 --- a/cirq-core/cirq/ops/phased_x_gate.py +++ b/cirq-core/cirq/ops/phased_x_gate.py @@ -12,10 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. """An `XPowGate` conjugated by `ZPowGate`s.""" + +from types import NotImplementedType from typing import AbstractSet, Any, cast, Dict, Optional, Sequence, Tuple, Union import math import numbers + import numpy as np import sympy @@ -23,7 +26,6 @@ from cirq import value, protocols from cirq._compat import proper_repr from cirq.ops import common_gates, raw_types -from cirq.type_workarounds import NotImplementedType @value.value_equality(manual_cls=True, approximate=True) @@ -130,7 +132,7 @@ def _trace_distance_bound_(self) -> Optional[float]: def _has_unitary_(self): return not self._is_parameterized_() - def _unitary_(self) -> Union[np.ndarray, NotImplementedType]: + def _unitary_(self) -> Optional[Union[np.ndarray, NotImplementedType]]: """See `cirq.SupportsUnitary`.""" if self._is_parameterized_(): return None diff --git a/cirq-core/cirq/ops/raw_types.py b/cirq-core/cirq/ops/raw_types.py index 5c67151a826..696868fe780 100644 --- a/cirq-core/cirq/ops/raw_types.py +++ b/cirq-core/cirq/ops/raw_types.py @@ -16,6 +16,7 @@ import abc import functools +from types import NotImplementedType from typing import ( cast, AbstractSet, @@ -42,7 +43,6 @@ from cirq import protocols, value from cirq._import import LazyLoader from cirq._compat import __cirq_debug__, _method_cache_name, cached_method -from cirq.type_workarounds import NotImplementedType from cirq.ops import control_values as cv # Lazy imports to break circular dependencies. @@ -879,7 +879,7 @@ def _mixture_(self) -> Sequence[Tuple[float, Any]]: def _has_kraus_(self) -> bool: return protocols.has_kraus(self.sub_operation) - def _kraus_(self) -> Union[Tuple[np.ndarray], NotImplementedType]: + def _kraus_(self) -> Union[Tuple[np.ndarray, ...], NotImplementedType]: return protocols.kraus(self.sub_operation, NotImplemented) @cached_method diff --git a/cirq-core/cirq/protocols/act_on_protocol.py b/cirq-core/cirq/protocols/act_on_protocol.py index 8ac4875c01c..87fedb38038 100644 --- a/cirq-core/cirq/protocols/act_on_protocol.py +++ b/cirq-core/cirq/protocols/act_on_protocol.py @@ -12,13 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. +from types import NotImplementedType from typing import Any, Optional, Sequence, TYPE_CHECKING, Union from typing_extensions import Protocol from cirq import ops from cirq._doc import doc_private -from cirq.type_workarounds import NotImplementedType if TYPE_CHECKING: import cirq diff --git a/cirq-core/cirq/protocols/apply_channel_protocol.py b/cirq-core/cirq/protocols/apply_channel_protocol.py index a6c8f283718..75c4b5e8b5f 100644 --- a/cirq-core/cirq/protocols/apply_channel_protocol.py +++ b/cirq-core/cirq/protocols/apply_channel_protocol.py @@ -14,6 +14,7 @@ """A protocol for implementing high performance channel evolutions.""" +from types import NotImplementedType from typing import Any, Iterable, Optional, Sequence, TypeVar, Tuple, Union import numpy as np @@ -24,7 +25,6 @@ from cirq.protocols.apply_unitary_protocol import apply_unitary, ApplyUnitaryArgs from cirq.protocols.kraus_protocol import kraus from cirq.protocols import qid_shape_protocol -from cirq.type_workarounds import NotImplementedType # This is a special indicator value used by the apply_channel method # to determine whether or not the caller provided a 'default' argument. It must diff --git a/cirq-core/cirq/protocols/apply_mixture_protocol.py b/cirq-core/cirq/protocols/apply_mixture_protocol.py index 121fc1b6dfd..5ff9414f5dd 100644 --- a/cirq-core/cirq/protocols/apply_mixture_protocol.py +++ b/cirq-core/cirq/protocols/apply_mixture_protocol.py @@ -14,6 +14,7 @@ """A protocol for implementing high performance mixture evolutions.""" +from types import NotImplementedType from typing import Any, cast, Iterable, Optional, Tuple, TypeVar, Union import numpy as np @@ -22,10 +23,8 @@ from cirq import linalg from cirq._doc import doc_private from cirq.protocols.apply_unitary_protocol import apply_unitary, ApplyUnitaryArgs - from cirq.protocols.mixture_protocol import mixture from cirq.protocols import qid_shape_protocol -from cirq.type_workarounds import NotImplementedType # This is a special indicator value used by the apply_mixture method # to determine whether or not the caller provided a 'default' argument. It must diff --git a/cirq-core/cirq/protocols/apply_unitary_protocol.py b/cirq-core/cirq/protocols/apply_unitary_protocol.py index 9cdbb96aa07..4decd6207bc 100644 --- a/cirq-core/cirq/protocols/apply_unitary_protocol.py +++ b/cirq-core/cirq/protocols/apply_unitary_protocol.py @@ -15,6 +15,7 @@ """A protocol for implementing high performance unitary left-multiplies.""" import warnings +from types import NotImplementedType from typing import Any, cast, Iterable, Optional, Sequence, Tuple, TYPE_CHECKING, TypeVar, Union import numpy as np @@ -24,7 +25,6 @@ from cirq._doc import doc_private from cirq.protocols import qid_shape_protocol from cirq.protocols.decompose_protocol import _try_decompose_into_operations_and_qubits -from cirq.type_workarounds import NotImplementedType if TYPE_CHECKING: import cirq diff --git a/cirq-core/cirq/protocols/commutes_protocol.py b/cirq-core/cirq/protocols/commutes_protocol.py index 41d97764930..003a9e895ed 100644 --- a/cirq-core/cirq/protocols/commutes_protocol.py +++ b/cirq-core/cirq/protocols/commutes_protocol.py @@ -13,6 +13,7 @@ # limitations under the License. """Protocol for determining commutativity.""" +from types import NotImplementedType from typing import Any, overload, TypeVar, Union import numpy as np @@ -20,7 +21,6 @@ from cirq import linalg from cirq._doc import doc_private -from cirq.type_workarounds import NotImplementedType # This is a special indicator value used by the unitary method to determine # whether or not the caller provided a 'default' argument. diff --git a/cirq-core/cirq/protocols/control_key_protocol.py b/cirq-core/cirq/protocols/control_key_protocol.py index d8c8a0ea589..5b3b90f80e7 100644 --- a/cirq-core/cirq/protocols/control_key_protocol.py +++ b/cirq-core/cirq/protocols/control_key_protocol.py @@ -13,13 +13,13 @@ # limitations under the License. """Protocol for object that have control keys.""" +from types import NotImplementedType from typing import Any, FrozenSet, TYPE_CHECKING, Union from typing_extensions import Protocol from cirq._doc import doc_private from cirq.protocols import measurement_key_protocol -from cirq.type_workarounds import NotImplementedType if TYPE_CHECKING: import cirq diff --git a/cirq-core/cirq/protocols/decompose_protocol.py b/cirq-core/cirq/protocols/decompose_protocol.py index c920a630830..99633e295be 100644 --- a/cirq-core/cirq/protocols/decompose_protocol.py +++ b/cirq-core/cirq/protocols/decompose_protocol.py @@ -15,6 +15,7 @@ import dataclasses import inspect from collections import defaultdict +from types import NotImplementedType from typing import ( TYPE_CHECKING, Any, @@ -37,7 +38,6 @@ from cirq import devices, ops from cirq._doc import doc_private from cirq.protocols import qid_shape_protocol -from cirq.type_workarounds import NotImplementedType if TYPE_CHECKING: import cirq diff --git a/cirq-core/cirq/protocols/json_serialization.py b/cirq-core/cirq/protocols/json_serialization.py index 070b4818ba0..92315403f51 100644 --- a/cirq-core/cirq/protocols/json_serialization.py +++ b/cirq-core/cirq/protocols/json_serialization.py @@ -17,6 +17,7 @@ import json import numbers import pathlib +from types import NotImplementedType from typing import ( Any, Callable, @@ -39,7 +40,6 @@ from typing_extensions import Protocol from cirq._doc import doc_private -from cirq.type_workarounds import NotImplementedType ObjectFactory = Union[Type, Callable[..., Any]] diff --git a/cirq-core/cirq/protocols/kraus_protocol.py b/cirq-core/cirq/protocols/kraus_protocol.py index bc661e5633d..695ebd2e75e 100644 --- a/cirq-core/cirq/protocols/kraus_protocol.py +++ b/cirq-core/cirq/protocols/kraus_protocol.py @@ -14,6 +14,7 @@ """Protocol and methods for obtaining Kraus representation of quantum channels.""" +from types import NotImplementedType from typing import Any, Sequence, Tuple, TypeVar, Union import warnings @@ -25,9 +26,6 @@ from cirq.protocols.mixture_protocol import has_mixture -from cirq.type_workarounds import NotImplementedType - - # This is a special indicator value used by the channel method to determine # whether or not the caller provided a 'default' argument. It must be of type # Sequence[np.ndarray] to ensure the method has the correct type signature in diff --git a/cirq-core/cirq/protocols/measurement_key_protocol.py b/cirq-core/cirq/protocols/measurement_key_protocol.py index 07b44d784a4..44cc2f93fd9 100644 --- a/cirq-core/cirq/protocols/measurement_key_protocol.py +++ b/cirq-core/cirq/protocols/measurement_key_protocol.py @@ -13,13 +13,13 @@ # limitations under the License. """Protocol for object that have measurement keys.""" +from types import NotImplementedType from typing import Any, FrozenSet, Mapping, Optional, Tuple, TYPE_CHECKING, Union from typing_extensions import Protocol from cirq import value from cirq._doc import doc_private -from cirq.type_workarounds import NotImplementedType if TYPE_CHECKING: import cirq diff --git a/cirq-core/cirq/protocols/mixture_protocol.py b/cirq-core/cirq/protocols/mixture_protocol.py index 5b3b79ae93e..fa70af631a2 100644 --- a/cirq-core/cirq/protocols/mixture_protocol.py +++ b/cirq-core/cirq/protocols/mixture_protocol.py @@ -13,6 +13,8 @@ # limitations under the License. """Protocol for objects that are mixtures (probabilistic combinations).""" + +from types import NotImplementedType from typing import Any, Sequence, Tuple, Union import numpy as np @@ -21,7 +23,6 @@ from cirq._doc import doc_private from cirq.protocols.decompose_protocol import _try_decompose_into_operations_and_qubits from cirq.protocols.has_unitary_protocol import has_unitary -from cirq.type_workarounds import NotImplementedType # This is a special indicator value used by the inverse method to determine # whether or not the caller provided a 'default' argument. diff --git a/cirq-core/cirq/protocols/qasm.py b/cirq-core/cirq/protocols/qasm.py index 9988df79b94..1700461f210 100644 --- a/cirq-core/cirq/protocols/qasm.py +++ b/cirq-core/cirq/protocols/qasm.py @@ -13,13 +13,13 @@ # limitations under the License. import string +from types import NotImplementedType from typing import TYPE_CHECKING, Union, Any, Tuple, TypeVar, Optional, Dict, Iterable from typing_extensions import Protocol from cirq import ops from cirq._doc import doc_private -from cirq.type_workarounds import NotImplementedType if TYPE_CHECKING: import cirq diff --git a/cirq-core/cirq/protocols/qid_shape_protocol.py b/cirq-core/cirq/protocols/qid_shape_protocol.py index 8f2e1f8c331..7e98d8a716a 100644 --- a/cirq-core/cirq/protocols/qid_shape_protocol.py +++ b/cirq-core/cirq/protocols/qid_shape_protocol.py @@ -12,13 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. +from types import NotImplementedType from typing import Any, Sequence, Tuple, TypeVar, Union from typing_extensions import Protocol from cirq import ops from cirq._doc import document, doc_private -from cirq.type_workarounds import NotImplementedType # This is a special indicator value used by the methods to determine whether or # not the caller provided a 'default' argument. It must be of type diff --git a/cirq-core/cirq/protocols/unitary_protocol.py b/cirq-core/cirq/protocols/unitary_protocol.py index 38de4043dbc..b197a918058 100644 --- a/cirq-core/cirq/protocols/unitary_protocol.py +++ b/cirq-core/cirq/protocols/unitary_protocol.py @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +from types import NotImplementedType from typing import Any, TypeVar, Union, Optional import numpy as np @@ -21,7 +22,6 @@ from cirq.protocols import qid_shape_protocol from cirq.protocols.apply_unitary_protocol import ApplyUnitaryArgs, apply_unitaries from cirq.protocols.decompose_protocol import _try_decompose_into_operations_and_qubits -from cirq.type_workarounds import NotImplementedType # This is a special indicator value used by the unitary method to determine # whether or not the caller provided a 'default' argument. It must be of type diff --git a/cirq-core/cirq/sim/clifford/stabilizer_simulation_state.py b/cirq-core/cirq/sim/clifford/stabilizer_simulation_state.py index bad4bca02c0..5707c9dc566 100644 --- a/cirq-core/cirq/sim/clifford/stabilizer_simulation_state.py +++ b/cirq-core/cirq/sim/clifford/stabilizer_simulation_state.py @@ -13,6 +13,7 @@ # limitations under the License. import abc +from types import NotImplementedType from typing import Any, cast, Generic, Optional, Sequence, TYPE_CHECKING, TypeVar, Union import numpy as np @@ -23,7 +24,6 @@ from cirq.ops.clifford_gate import SingleQubitCliffordGate from cirq.protocols import has_unitary, num_qubits, unitary from cirq.sim.simulation_state import SimulationState -from cirq.type_workarounds import NotImplementedType if TYPE_CHECKING: import cirq diff --git a/cirq-core/cirq/sim/simulation_state_base.py b/cirq-core/cirq/sim/simulation_state_base.py index 684813f07d5..8cf9d0a85c5 100644 --- a/cirq-core/cirq/sim/simulation_state_base.py +++ b/cirq-core/cirq/sim/simulation_state_base.py @@ -13,6 +13,7 @@ # limitations under the License. """An interface for quantum states as targets for operations.""" import abc +from types import NotImplementedType from typing import ( Any, Dict, @@ -32,7 +33,6 @@ import numpy as np from cirq import protocols, value -from cirq.type_workarounds import NotImplementedType if TYPE_CHECKING: import cirq diff --git a/cirq-core/cirq/testing/consistent_protocols_test.py b/cirq-core/cirq/testing/consistent_protocols_test.py index 2b1c4572967..330c498a2f5 100644 --- a/cirq-core/cirq/testing/consistent_protocols_test.py +++ b/cirq-core/cirq/testing/consistent_protocols_test.py @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +from types import NotImplementedType from typing import AbstractSet, Sequence, Union, List, Tuple import pytest @@ -21,7 +22,6 @@ import cirq from cirq._compat import proper_repr -from cirq.type_workarounds import NotImplementedType import cirq.testing.consistent_controlled_gate_op_test as controlled_gate_op_test diff --git a/cirq-core/cirq/type_workarounds.py b/cirq-core/cirq/type_workarounds.py deleted file mode 100644 index 6d903f65925..00000000000 --- a/cirq-core/cirq/type_workarounds.py +++ /dev/null @@ -1,23 +0,0 @@ -# Copyright 2018 The Cirq Developers -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Workarounds for deficiencies in python's typing system.""" - -from typing import Any - -# At the moment there's no reliable way to say 'NotImplementedType'. -# - type(NotImplemented) causes mypy to error. -# - Just NotImplemented causes runtime errors (it's not a type). -# - The string "NotImplemented" causes runtime errors (in some python versions). -NotImplementedType = Any