Fix more typing issues - #7388
Merged
Merged
Conversation
dstrain115
commented
May 29, 2025
Collaborator
- This is the result of adding "-> None" to a bunch of tests and fixing all the issues that result.
- This is the result of adding "-> None" to a bunch of tests and fixing all the issues that result.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #7388 +/- ##
=======================================
Coverage 98.68% 98.68%
=======================================
Files 1112 1112
Lines 97623 97703 +80
=======================================
+ Hits 96340 96420 +80
Misses 1283 1283 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Collaborator
|
We can narrow the diff --git a/cirq-core/cirq/circuits/circuit_operation_test.py b/cirq-core/cirq/circuits/circuit_operation_test.py
index af236f2e6..947cd8470 100644
--- a/cirq-core/cirq/circuits/circuit_operation_test.py
+++ b/cirq-core/cirq/circuits/circuit_operation_test.py
@@ -62,3 +62,3 @@ def test_circuit_type() -> None:
with pytest.raises(TypeError, match='Expected circuit of type FrozenCircuit'):
- _ = cirq.CircuitOperation(circuit) # type: ignore
+ _ = cirq.CircuitOperation(circuit) # type: ignore[arg-type]
@@ -197,3 +197,3 @@ def test_with_qubits() -> None:
with pytest.raises(TypeError, match='must be a function or dict'):
- _ = op_base.with_qubit_mapping('bad arg') # type: ignore
+ _ = op_base.with_qubit_mapping('bad arg') # type: ignore[arg-type]
diff --git a/cirq-core/cirq/circuits/frozen_circuit_test.py b/cirq-core/cirq/circuits/frozen_circuit_test.py
index caa4f4200..52b40900f 100644
--- a/cirq-core/cirq/circuits/frozen_circuit_test.py
+++ b/cirq-core/cirq/circuits/frozen_circuit_test.py
@@ -92,3 +92,3 @@ def test_immutable() -> None:
):
- c.moments = (cirq.Moment(cirq.H(q)), cirq.Moment(cirq.X(q))) # type: ignore
+ c.moments = (cirq.Moment(cirq.H(q)), cirq.Moment(cirq.X(q))) # type: ignore[misc]
diff --git a/cirq-core/cirq/circuits/text_diagram_drawer_test.py b/cirq-core/cirq/circuits/text_diagram_drawer_test.py
index 1a5e8b9e9..ae3b1c955 100644
--- a/cirq-core/cirq/circuits/text_diagram_drawer_test.py
+++ b/cirq-core/cirq/circuits/text_diagram_drawer_test.py
@@ -240,5 +240,5 @@ def test_drawer_copy() -> None:
}
- orig_drawer = TextDiagramDrawer(**kwargs) # type: ignore
+ orig_drawer = TextDiagramDrawer(**kwargs) # type: ignore[arg-type]
- same_drawer = TextDiagramDrawer(**kwargs) # type: ignore
+ same_drawer = TextDiagramDrawer(**kwargs) # type: ignore[arg-type]
assert orig_drawer == same_drawer
@@ -338,3 +338,3 @@ AB D
- vstacked = TextDiagramDrawer.vstack((dd, d), padding_resolver=max) # type: ignore
+ vstacked = TextDiagramDrawer.vstack((dd, d), padding_resolver=max) # type: ignore[arg-type]
expected = """
@@ -352,3 +352,3 @@ A B
- hstacked = TextDiagramDrawer.hstack((d, dd), padding_resolver=max) # type: ignore
+ hstacked = TextDiagramDrawer.hstack((d, dd), padding_resolver=max) # type: ignore[arg-type]
expected = """
@@ -362,3 +362,3 @@ AB D
- vstacked_min = TextDiagramDrawer.vstack((dd, d), padding_resolver=min) # type:ignore
+ vstacked_min = TextDiagramDrawer.vstack((dd, d), padding_resolver=min) # type: ignore[arg-type]
expected = """
@@ -376,3 +376,3 @@ AB
- hstacked_min = TextDiagramDrawer.hstack((d, dd), padding_resolver=min) # type:ignore
+ hstacked_min = TextDiagramDrawer.hstack((d, dd), padding_resolver=min) # type: ignore[arg-type]
expected = """
diff --git a/cirq-core/cirq/contrib/custom_simulators/custom_state_simulator_test.py b/cirq-core/cirq/contrib/custom_simulators/custom_state_simulator_test.py
index 3fd5f2fb8..bc5730948 100644
--- a/cirq-core/cirq/contrib/custom_simulators/custom_state_simulator_test.py
+++ b/cirq-core/cirq/contrib/custom_simulators/custom_state_simulator_test.py
@@ -71,3 +71,3 @@ def test_basis_state_simulator() -> None:
assert r.measurements == {'a': np.array([1]), 'b': np.array([2])}
- assert r._final_simulator_state._state.basis == [2, 2] # type: ignore
+ assert r._final_simulator_state._state.basis == [2, 2] # type: ignore[attr-defined]
@@ -81,3 +81,3 @@ def test_built_in_states() -> None:
assert np.allclose(
- r._final_simulator_state._state._state_vector, # type: ignore
+ r._final_simulator_state._state._state_vector, # type: ignore[attr-defined]
[[0, 0, 0], [0, 0, 0], [0, 0, 1]],
@@ -108,3 +108,3 @@ def test_noise() -> None:
assert r.measurements == {'a': np.array([2]), 'b': np.array([2])}
- assert r._final_simulator_state._state.basis == [1, 2] # type: ignore
+ assert r._final_simulator_state._state.basis == [1, 2] # type: ignore[attr-defined]
diff --git a/cirq-core/cirq/ops/clifford_gate_test.py b/cirq-core/cirq/ops/clifford_gate_test.py
index 0e63a1b12..ecded719a 100644
--- a/cirq-core/cirq/ops/clifford_gate_test.py
+++ b/cirq-core/cirq/ops/clifford_gate_test.py
@@ -739,3 +739,3 @@ def test_clifford_gate_from_tableau() -> None:
with pytest.raises(ValueError, match="Input argument has to be a CliffordTableau instance."):
- cirq.CliffordGate.from_clifford_tableau(1) # type: ignore
+ cirq.CliffordGate.from_clifford_tableau(1) # type: ignore[arg-type]
diff --git a/cirq-core/cirq/ops/common_gate_families_test.py b/cirq-core/cirq/ops/common_gate_families_test.py
index f8bc7b74e..080113aa1 100644
--- a/cirq-core/cirq/ops/common_gate_families_test.py
+++ b/cirq-core/cirq/ops/common_gate_families_test.py
@@ -61,5 +61,5 @@ def test_any_integer_power_gate_family() -> None:
with pytest.raises(ValueError, match='subclass of `cirq.EigenGate`'):
- cirq.AnyIntegerPowerGateFamily(gate=cirq.testing.SingleQubitGate) # type: ignore
+ cirq.AnyIntegerPowerGateFamily(gate=cirq.testing.SingleQubitGate) # type: ignore[arg-type]
with pytest.raises(ValueError, match='subclass of `cirq.EigenGate`'):
- cirq.AnyIntegerPowerGateFamily(gate=CustomXPowGate()) # type: ignore
+ cirq.AnyIntegerPowerGateFamily(gate=CustomXPowGate()) # type: ignore[arg-type]
eq = cirq.testing.EqualsTester()
@@ -67,3 +67,5 @@ def test_any_integer_power_gate_family() -> None:
eq.add_equality_group(gate_family)
- eq.add_equality_group(cirq.AnyIntegerPowerGateFamily(cirq.EigenGate)) # type: ignore
+ eq.add_equality_group(
+ cirq.AnyIntegerPowerGateFamily(cirq.EigenGate) # type: ignore[type-abstract]
+ )
cirq.testing.assert_equivalent_repr(gate_family)
diff --git a/cirq-core/cirq/ops/fourier_transform_test.py b/cirq-core/cirq/ops/fourier_transform_test.py
index 0d0066603..fd490197f 100644
--- a/cirq-core/cirq/ops/fourier_transform_test.py
+++ b/cirq-core/cirq/ops/fourier_transform_test.py
@@ -109,4 +109,4 @@ def test_qft() -> None:
np.testing.assert_allclose(
- cirq.unitary(cirq.qft(*cirq.LineQubit.range(2)) ** -1), # type:ignore
- arr, # type: ignore
+ cirq.unitary(cirq.qft(*cirq.LineQubit.range(2)) ** -1), # type: ignore[operator]
+ arr, # type: ignore[arg-type]
atol=1e-8,
@@ -123,3 +123,3 @@ def test_inverse() -> None:
a, b, c = cirq.LineQubit.range(3)
- assert cirq.qft(a, b, c, inverse=True) == cirq.qft(a, b, c) ** -1 # type:ignore
+ assert cirq.qft(a, b, c, inverse=True) == cirq.qft(a, b, c) ** -1 # type: ignore[operator]
assert cirq.qft(a, b, c, inverse=True, without_reverse=True) == cirq.inverse(
diff --git a/cirq-core/cirq/ops/gate_operation_test.py b/cirq-core/cirq/ops/gate_operation_test.py
index d7dcf129f..d9c3b62b9 100644
--- a/cirq-core/cirq/ops/gate_operation_test.py
+++ b/cirq-core/cirq/ops/gate_operation_test.py
@@ -379,5 +379,5 @@ def test_mul() -> None:
r = GateRMul().on(q)
- assert 2 * r == 3 # type: ignore
+ assert 2 * r == 3 # type: ignore[operator]
with pytest.raises(TypeError):
- _ = r * 2 # type: ignore
+ _ = r * 2 # type: ignore[operator]
@@ -385,9 +385,9 @@ def test_mul() -> None:
m = GateMul().on(q)
- assert m * 2 == 5 # type: ignore
+ assert m * 2 == 5 # type: ignore[operator]
with pytest.raises(TypeError):
- _ = 2 * m # type: ignore
+ _ = 2 * m # type: ignore[operator]
# Handles the symmetric type case correctly.
- assert m * m == 6 # type: ignore
- assert r * r == 4 # type: ignore
+ assert m * m == 6 # type: ignore[operator]
+ assert r * r == 4 # type: ignore[operator]
diff --git a/cirq-core/cirq/ops/identity_test.py b/cirq-core/cirq/ops/identity_test.py
index d5be1933f..f7141fe29 100644
--- a/cirq-core/cirq/ops/identity_test.py
+++ b/cirq-core/cirq/ops/identity_test.py
@@ -180,3 +180,3 @@ def test_identity_global() -> None:
# The user forgot to expand the list for example.
- cirq.identity_each(qubits) # type: ignore
+ cirq.identity_each(qubits) # type: ignore[arg-type]
diff --git a/cirq-core/cirq/ops/op_tree_test.py b/cirq-core/cirq/ops/op_tree_test.py
index bf33d4818..74b55f381 100644
--- a/cirq-core/cirq/ops/op_tree_test.py
+++ b/cirq-core/cirq/ops/op_tree_test.py
@@ -51,7 +51,7 @@ def test_flatten_op_tree() -> None:
with pytest.raises(TypeError):
- _ = list(cirq.flatten_op_tree(None)) # type: ignore
+ _ = list(cirq.flatten_op_tree(None)) # type: ignore[arg-type]
with pytest.raises(TypeError):
- _ = list(cirq.flatten_op_tree(5)) # type: ignore
+ _ = list(cirq.flatten_op_tree(5)) # type: ignore[arg-type]
with pytest.raises(TypeError):
- _ = list(cirq.flatten_op_tree([operations[0], (4,)])) # type: ignore
+ _ = list(cirq.flatten_op_tree([operations[0], (4,)])) # type: ignore[list-item]
@@ -70,7 +70,7 @@ def test_flatten_to_ops_or_moments() -> None:
with pytest.raises(TypeError):
- _ = list(cirq.flatten_to_ops_or_moments(None)) # type: ignore
+ _ = list(cirq.flatten_to_ops_or_moments(None)) # type: ignore[arg-type]
with pytest.raises(TypeError):
- _ = list(cirq.flatten_to_ops_or_moments(5)) # type: ignore
+ _ = list(cirq.flatten_to_ops_or_moments(5)) # type: ignore[arg-type]
with pytest.raises(TypeError):
- _ = list(cirq.flatten_to_ops_or_moments([operations[0], (4,)])) # type: ignore
+ _ = list(cirq.flatten_to_ops_or_moments([operations[0], (4,)])) # type: ignore[list-item]
@@ -99,7 +99,7 @@ def test_freeze_op_tree() -> None:
with pytest.raises(TypeError):
- cirq.freeze_op_tree(None) # type: ignore
+ cirq.freeze_op_tree(None) # type: ignore[arg-type]
with pytest.raises(TypeError):
- cirq.freeze_op_tree(5) # type: ignore
+ cirq.freeze_op_tree(5) # type: ignore[arg-type]
with pytest.raises(TypeError):
- _ = cirq.freeze_op_tree([operations[0], (4,)]) # type: ignore
+ _ = cirq.freeze_op_tree([operations[0], (4,)]) # type: ignore[list-item]
@@ -108,5 +108,5 @@ def test_transform_bad_tree() -> None:
with pytest.raises(TypeError):
- _ = list(cirq.transform_op_tree(None)) # type: ignore
+ _ = list(cirq.transform_op_tree(None)) # type: ignore[arg-type]
with pytest.raises(TypeError):
- _ = list(cirq.transform_op_tree(5)) # type: ignore
+ _ = list(cirq.transform_op_tree(5)) # type: ignore[arg-type]
with pytest.raises(TypeError):
diff --git a/cirq-core/cirq/ops/qubit_order_test.py b/cirq-core/cirq/ops/qubit_order_test.py
index db129f52b..a66913ae7 100644
--- a/cirq-core/cirq/ops/qubit_order_test.py
+++ b/cirq-core/cirq/ops/qubit_order_test.py
@@ -132,2 +132,2 @@ def test_qubit_order_invalid() -> None:
with pytest.raises(ValueError, match="Don't know how to interpret <5> as a Basis."):
- _ = cirq.QubitOrder.as_qubit_order(5) # type: ignore
+ _ = cirq.QubitOrder.as_qubit_order(5) # type: ignore[arg-type]
diff --git a/cirq-core/cirq/ops/raw_types_test.py b/cirq-core/cirq/ops/raw_types_test.py
index 19c0cffd1..e023e7c8b 100644
--- a/cirq-core/cirq/ops/raw_types_test.py
+++ b/cirq-core/cirq/ops/raw_types_test.py
@@ -65,3 +65,3 @@ def test_wrapped_qid() -> None:
assert ValidQubit('a').with_dimension(3).with_dimension(4) == ValidQubit('a').with_dimension(4)
- assert ValidQubit('a').with_dimension(3).qubit == ValidQubit('a') # type: ignore
+ assert ValidQubit('a').with_dimension(3).qubit == ValidQubit('a') # type: ignore[attr-defined]
assert ValidQubit('a').with_dimension(3) == ValidQubit('a').with_dimension(3)
@@ -76,3 +76,3 @@ def test_wrapped_qid() -> None:
- assert ValidQubit('zz').with_dimension(3)._json_dict_() == { # type: ignore
+ assert ValidQubit('zz').with_dimension(3)._json_dict_() == { # type: ignore[attr-defined]
'qubit': ValidQubit('zz'),
@@ -212,3 +212,3 @@ def test_default_validation_and_inverse() -> None:
assert cirq.decompose(i) == [cirq.X(a), cirq.S(b) ** -1, cirq.Z(a)]
- assert [*i._decompose_()] == [cirq.X(a), cirq.S(b) ** -1, cirq.Z(a)] # type: ignore
+ assert [*i._decompose_()] == [cirq.X(a), cirq.S(b) ** -1, cirq.Z(a)] # type: ignore[misc]
gate = i.gate
|
pavoljuhas
requested changes
May 29, 2025
pavoljuhas
left a comment
Collaborator
There was a problem hiding this comment.
ruff finds some more functions in the touched files that lack return annotations (ANN201):
$ ruff check --select=ANN201 $(git diff --name-only --merge-base main)
...
Found 24 errors.
No fixes available (12 hidden fixes can be enabled with the `--unsafe-fixes` option).Otherwise LGTM.
Collaborator
Author
|
@pavoljuhas Applied your patch. Will do remaining functions in a later PR. This one is already big enough. |
pavoljuhas
approved these changes
May 30, 2025
This was referenced May 30, 2025
BichengYing
pushed a commit
to BichengYing/Cirq
that referenced
this pull request
Jun 20, 2025
- This is the result of adding "-> None" to a bunch of tests and fixing all the issues that result.
This was referenced Aug 5, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.