Skip to content

Commit fed3908

Browse files
committed
Fix mypy type errors and remove typos
1 parent ed7d8fc commit fed3908

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

Diff for: cirq-core/cirq/transformers/transformer_api.py

+12
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from typing import (
2323
cast,
2424
Any,
25+
Callable,
2526
Tuple,
2627
Hashable,
2728
List,
@@ -30,6 +31,7 @@
3031
Type,
3132
TYPE_CHECKING,
3233
TypeVar,
34+
Union,
3335
)
3436
from typing_extensions import Protocol
3537

@@ -235,6 +237,16 @@ def __call__(
235237

236238
_TRANSFORMER_T = TypeVar('_TRANSFORMER_T', bound=TRANSFORMER)
237239
_TRANSFORMER_CLS_T = TypeVar('_TRANSFORMER_CLS_T', bound=Type[TRANSFORMER])
240+
_TRANSFORMER_OR_CLS_T = TypeVar(
241+
'_TRANSFORMER_OR_CLS_T', bound=Union[TRANSFORMER, Type[TRANSFORMER]]
242+
)
243+
244+
245+
@overload
246+
def transformer(
247+
*, add_support_for_deep: bool = False
248+
) -> Callable[[_TRANSFORMER_OR_CLS_T], _TRANSFORMER_OR_CLS_T]:
249+
pass
238250

239251

240252
@overload

Diff for: cirq-core/cirq/transformers/transformer_api_test.py

+3-8
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,9 @@ def make_transformer_func(add_support_for_deep: bool = False) -> cirq.TRANSFORME
8989
def mock_tranformer_func(
9090
circuit: cirq.AbstractCircuit, *, context: Optional[cirq.TransformerContext] = None
9191
) -> cirq.Circuit:
92-
print("CALLED:", circuit, context, sep="\n\n----------\n\n")
9392
my_mock(circuit, context)
9493
return circuit.unfreeze()
9594

96-
# mock_transformer = mock_tranformer_func(add_support_for_deep)
9795
mock_tranformer_func.mock = my_mock # type: ignore
9896
return mock_tranformer_func
9997

@@ -141,9 +139,6 @@ def test_transformer_decorator_with_defaults(transformer):
141139
transformer.mock.assert_called_with(circuit, context, 1e-2, CustomArg(12))
142140

143141

144-
# from unittest.mock import patch, call
145-
146-
147142
@pytest.mark.parametrize(
148143
'transformer, supports_deep',
149144
[
@@ -154,9 +149,9 @@ def test_transformer_decorator_with_defaults(transformer):
154149
],
155150
)
156151
def test_transformer_decorator_adds_support_for_deep(transformer, supports_deep):
157-
q1, q2 = cirq.LineQubit.range(2)
158-
c_nested_x = cirq.FrozenCircuit(cirq.X(q1))
159-
c_nested_y = cirq.FrozenCircuit(cirq.Y(q1))
152+
q = cirq.NamedQubit("q")
153+
c_nested_x = cirq.FrozenCircuit(cirq.X(q))
154+
c_nested_y = cirq.FrozenCircuit(cirq.Y(q))
160155
c_nested_xy = cirq.FrozenCircuit(
161156
cirq.CircuitOperation(c_nested_x).repeat(5).with_tags("ignore"),
162157
cirq.CircuitOperation(c_nested_y).repeat(7).with_tags("preserve_tag"),

0 commit comments

Comments
 (0)