Skip to content

Commit 15345b4

Browse files
authored
Enable pylint and ruff check for unused suppression comments (#7412)
No change in the effective code. - ruff - fix RUF100 - unused-noqa directive - pylint - fix useless-suppression - pylint - remove unpaired pylint-enable directives - pylint - enable `line-too-long` which was disabled above - pylint - enable in `cirq.transformers.merge_k_qubit_gates_test`
1 parent 4b118d0 commit 15345b4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+20
-129
lines changed

cirq-core/cirq/_compat_test.py

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -202,13 +202,11 @@ def old_func(*args, **kwargs):
202202
old_func(1, 2)
203203

204204
with pytest.raises(AssertionError, match='deadline should match vX.Y'):
205-
# pylint: disable=unused-variable
205+
206206
@deprecated(deadline='invalid', fix='Roll some dice.')
207207
def badly_deprecated_func(*args, **kwargs): # pragma: no cover
208208
return new_func(*args, **kwargs)
209209

210-
# pylint: enable=unused-variable
211-
212210

213211
def test_deprecated_parameter():
214212
@deprecated_parameter(
@@ -234,20 +232,16 @@ def f(new_count):
234232
'Double it yourself.',
235233
deadline='v1.2',
236234
):
237-
# pylint: disable=unexpected-keyword-arg
238235
# pylint: disable=no-value-for-parameter
239236
assert f(double_count=1) == 2
240237
# pylint: enable=no-value-for-parameter
241-
# pylint: enable=unexpected-keyword-arg
242238

243239
with pytest.raises(
244240
ValueError, match='During testing using Cirq deprecated functionality is not allowed'
245241
):
246-
# pylint: disable=unexpected-keyword-arg
247242
# pylint: disable=no-value-for-parameter
248243
f(double_count=1)
249244
# pylint: enable=no-value-for-parameter
250-
# pylint: enable=unexpected-keyword-arg
251245

252246
with pytest.raises(AssertionError, match='deadline should match vX.Y'):
253247

@@ -259,12 +253,9 @@ def f(new_count):
259253
match=lambda args, kwargs: 'double_count' in kwargs,
260254
rewrite=lambda args, kwargs: (args, {'new_count': kwargs['double_count'] * 2}),
261255
)
262-
# pylint: disable=unused-variable
263256
def f_with_badly_deprecated_param(new_count): # pragma: no cover
264257
return new_count
265258

266-
# pylint: enable=unused-variable
267-
268259

269260
@duet.sync
270261
async def test_deprecated_parameter_async_function():
@@ -293,11 +284,9 @@ async def f(new_count):
293284
'Double it yourself.',
294285
deadline='v1.2',
295286
):
296-
# pylint: disable=unexpected-keyword-arg
297287
# pylint: disable=no-value-for-parameter
298288
assert await f(double_count=1) == 2
299289
# pylint: enable=no-value-for-parameter
300-
# pylint: enable=unexpected-keyword-arg
301290

302291

303292
def test_wrap_module():
@@ -587,7 +576,6 @@ def _repeated_import_path():
587576

588577
def _type_repr_in_deprecated_module():
589578
# initialize the DeprecatedModuleFinders
590-
# pylint: disable=unused-import
591579
import cirq.testing._compat_test_data.fake_a as mod_a
592580

593581
expected_repr = "<class 'cirq.testing._compat_test_data.module_a.types.SampleType'>"
@@ -763,8 +751,6 @@ def test_metadata_search_path():
763751

764752
def _test_metadata_search_path_inner(): # pragma: no cover
765753
# initialize the DeprecatedModuleFinders
766-
# pylint: disable=unused-import
767-
768754
assert importlib.metadata.metadata('numpy')
769755

770756

@@ -805,7 +791,6 @@ def test_type_repr_in_new_module():
805791

806792
def _test_type_repr_in_new_module_inner():
807793
# initialize the DeprecatedModuleFinders
808-
# pylint: disable=unused-import
809794
import cirq.testing._compat_test_data.module_a as mod_a
810795

811796
expected_repr = "<class 'cirq.testing._compat_test_data.module_a.types.SampleType'>"
@@ -875,7 +860,6 @@ def test_new_module_is_top_level():
875860

876861
def _test_new_module_is_top_level_inner():
877862
# sets up the DeprecationFinders
878-
# pylint: disable=unused-import
879863
import time
880864

881865
# imports a top level module that was also deprecated

cirq-core/cirq/circuits/circuit.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,6 @@ def _decompose_(self) -> cirq.OP_TREE:
233233
"""See `cirq.SupportsDecompose`."""
234234
return self.all_operations()
235235

236-
# pylint: disable=function-redefined
237236
@overload
238237
def __getitem__(self, key: int) -> cirq.Moment:
239238
pass
@@ -277,8 +276,6 @@ def __getitem__(self, key):
277276

278277
raise TypeError('__getitem__ called with key not of type slice, int, or tuple.')
279278

280-
# pylint: enable=function-redefined
281-
282279
def __str__(self) -> str:
283280
return self.to_text_diagram()
284281

@@ -1895,7 +1892,6 @@ def copy(self) -> Circuit:
18951892
copied_circuit._placement_cache = None
18961893
return copied_circuit
18971894

1898-
# pylint: disable=function-redefined
18991895
@overload
19001896
def __setitem__(self, key: int, value: cirq.Moment):
19011897
pass
@@ -1916,8 +1912,6 @@ def __setitem__(self, key, value):
19161912
self._moments[key] = value
19171913
self._mutated()
19181914

1919-
# pylint: enable=function-redefined
1920-
19211915
def __delitem__(self, key: int | slice):
19221916
del self._moments[key]
19231917
self._mutated()

cirq-core/cirq/circuits/moment.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,6 @@ def __sub__(self, other: cirq.OP_TREE) -> cirq.Moment:
538538
)
539539
return Moment(new_ops)
540540

541-
# pylint: disable=function-redefined
542541
@overload
543542
def __getitem__(self, key: raw_types.Qid) -> cirq.Operation:
544543
pass

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,11 @@
164164
│ │ │ │
165165
3: ─────────────█───1↦0───────█───1↦0─────────────
166166
""",
167-
('decomposed', cca.BipartiteGraphType.COMPLETE, 3):
168-
# pylint: disable=line-too-long
169-
"""
167+
(
168+
'decomposed',
169+
cca.BipartiteGraphType.COMPLETE,
170+
3,
171+
): """
170172
0: ───────────────────────█───0↦1───────────────────────────█───0↦1───────────────────────
171173
│ │ │ │
172174
1: ─────────────█───0↦1───█───1↦0───█───0↦1───────█───0↦1───█───1↦0───█───0↦1─────────────
@@ -202,7 +204,6 @@
202204
7: ─────────────────────────────────█───1↦0───────────────────────────────────────────────█───1↦0─────────────────────────────────
203205
204206
""",
205-
# pylint: enable=line-too-long
206207
(
207208
'decomposed',
208209
cca.BipartiteGraphType.MATCHING,

cirq-core/cirq/contrib/quirk/quirk_gate.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ def single_qubit_matrix_gate(matrix: np.ndarray | None) -> QuirkOp | None:
113113
if matrix is None or matrix.shape[0] != 2:
114114
return None
115115

116-
# pylint: disable=consider-using-f-string
117116
matrix = matrix.round(6)
118117
matrix_repr = '{{%s+%si,%s+%si},{%s+%si,%s+%si}}' % (
119118
np.real(matrix[0, 0]),

cirq-core/cirq/linalg/decompositions.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ def unitary_eig(
130130
return R.diagonal(), V
131131

132132

133-
# pylint: enable=missing-raises-doc
134133
def map_eigenvalues(
135134
matrix: np.ndarray, func: Callable[[complex], complex], *, atol: float = 1e-8
136135
) -> np.ndarray:

cirq-core/cirq/ops/clifford_gate.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -747,11 +747,7 @@ def __pow__(self, exponent: float) -> SingleQubitCliffordGate:
747747

748748
return NotImplemented
749749

750-
def _act_on_(
751-
self,
752-
sim_state: cirq.SimulationStateBase, # pylint: disable=unused-argument
753-
qubits: Sequence[cirq.Qid], # pylint: disable=unused-argument
754-
):
750+
def _act_on_(self, sim_state: cirq.SimulationStateBase, qubits: Sequence[cirq.Qid]):
755751
# TODO(#5256) Add the implementation of _act_on_ with CliffordTableauSimulationState.
756752
return NotImplemented
757753

cirq-core/cirq/ops/eigen_gate.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,9 @@ def _with_exponent(self, exponent: value.TParamVal) -> EigenGate:
128128
Child classes should override this method if they have an __init__
129129
method with a differing signature.
130130
"""
131-
# pylint: disable=unexpected-keyword-arg
132131
if self._global_shift == 0:
133132
return type(self)(exponent=exponent)
134133
return type(self)(exponent=exponent, global_shift=self._global_shift)
135-
# pylint: enable=unexpected-keyword-arg
136134

137135
def _diagram_exponent(
138136
self, args: protocols.CircuitDiagramInfoArgs, *, ignore_global_phase: bool = True

cirq-core/cirq/ops/measure_util.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,6 @@ def measure_paulistring_terms(
9090
return [PauliMeasurementGate([pauli_basis[q]], key=key_func(q)).on(q) for q in pauli_basis]
9191

9292

93-
# pylint: disable=function-redefined
94-
95-
9693
@overload
9794
def measure(
9895
*target: raw_types.Qid,
@@ -205,6 +202,3 @@ def measure_each(
205202
)
206203
qubitsequence = qubits[0] if one_iterable_arg else qubits
207204
return [MeasurementGate(1, key_func(q), qid_shape=(q.dimension,)).on(q) for q in qubitsequence]
208-
209-
210-
# pylint: enable=function-redefined

cirq-core/cirq/ops/pauli_string.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,6 @@ def equal_up_to_coefficient(self, other: cirq.PauliString) -> bool:
232232
def __getitem__(self, key: TKey) -> pauli_gates.Pauli:
233233
return self._qubit_pauli_map[key]
234234

235-
# pylint: disable=function-redefined
236235
@overload
237236
def get(self, key: Any, default: None = None) -> pauli_gates.Pauli | None:
238237
pass
@@ -281,8 +280,6 @@ def __mul__(self, other):
281280
)
282281
return NotImplemented
283282

284-
# pylint: enable=function-redefined
285-
286283
@property
287284
def gate(self) -> cirq.DensePauliString:
288285
"""Returns a `cirq.DensePauliString`"""
@@ -897,9 +894,7 @@ def dense(self, qubits: Sequence[TKey]) -> cirq.DensePauliString:
897894

898895
if not self.keys() <= set(qubits):
899896
raise ValueError('not self.keys() <= set(qubits)')
900-
# pylint: disable=too-many-function-args
901897
pauli_mask = [self.get(q, identity.I) for q in qubits]
902-
# pylint: enable=too-many-function-args
903898
return dense_pauli_string.DensePauliString(pauli_mask, coefficient=self.coefficient)
904899

905900
def conjugated_by(self, clifford: cirq.OP_TREE) -> PauliString:
@@ -1349,7 +1344,6 @@ def __setitem__(self, key: TKey, value: cirq.PAULI_GATE_LIKE):
13491344
def __delitem__(self, key: TKey):
13501345
del self.pauli_int_dict[key]
13511346

1352-
# pylint: disable=function-redefined
13531347
@overload
13541348
def get(self, key: TKey, default: None = None) -> cirq.Pauli | None:
13551349
pass
@@ -1363,7 +1357,6 @@ def get(self, key: TKey, default=None) -> cirq.Pauli | TDefault | None:
13631357
result = self.pauli_int_dict.get(key, None)
13641358
return default if result is None else _INT_TO_PAULI[result - 1]
13651359

1366-
# pylint: enable=function-redefined
13671360
def inplace_before(self, ops: cirq.OP_TREE) -> cirq.MutablePauliString:
13681361
r"""Propagates the pauli string from after to before a Clifford effect.
13691362

cirq-core/cirq/ops/pauli_string_test.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,9 +337,7 @@ def test_get(qubit_pauli_map):
337337
assert qubit_pauli_map.get(key) == pauli_string.get(key)
338338
assert qubit_pauli_map.get(other) is None
339339
assert pauli_string.get(other) is None
340-
# pylint: disable=too-many-function-args
341340
assert qubit_pauli_map.get(other, 5) == pauli_string.get(other, 5) == 5
342-
# pylint: enable=too-many-function-args
343341

344342

345343
@pytest.mark.parametrize('qubit_pauli_map', _sample_qubit_pauli_maps())

cirq-core/cirq/ops/three_qubit_gates.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
)
3838

3939
if TYPE_CHECKING:
40-
# pylint: disable=unused-import
4140
import cirq
4241

4342

cirq-core/cirq/protocols/circuit_diagram_info_protocol.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,6 @@ def _op_info_with_fallback(
357357
return protocols.CircuitDiagramInfo(wire_symbols=symbols)
358358

359359

360-
# pylint: disable=function-redefined
361360
@overload
362361
def circuit_diagram_info(
363362
val: Any, args: CircuitDiagramInfoArgs | None = None
@@ -429,6 +428,3 @@ def circuit_diagram_info(
429428
f"object of type '{type(val)}' does have a _circuit_diagram_info_ "
430429
"method, but it returned NotImplemented."
431430
)
432-
433-
434-
# pylint: enable=function-redefined

cirq-core/cirq/protocols/decompose_protocol.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -308,9 +308,6 @@ def decompose(
308308
return [*_decompose_dfs(val, args)]
309309

310310

311-
# pylint: disable=function-redefined
312-
313-
314311
@overload
315312
def decompose_once(val: Any, **kwargs) -> list[cirq.Operation]:
316313
pass
@@ -452,9 +449,6 @@ def decompose_once_with_qubits(
452449
return decompose_once(val, default, tuple(qubits), flatten=flatten, context=context)
453450

454451

455-
# pylint: enable=function-redefined
456-
457-
458452
def _try_decompose_into_operations_and_qubits(
459453
val: Any,
460454
) -> tuple[list[cirq.Operation] | None, Sequence[cirq.Qid], tuple[int, ...]]:

cirq-core/cirq/protocols/inverse_protocol.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
TDefault = TypeVar('TDefault')
2929

3030

31-
# pylint: disable=function-redefined
3231
@overload
3332
def inverse(val: cirq.Gate) -> cirq.Gate:
3433
pass
@@ -100,7 +99,6 @@ def inverse(val: Any, default: Any = RaiseTypeErrorIfNotProvided) -> Any:
10099
# Check if object defines an inverse via __pow__.
101100
raiser = getattr(val, '__pow__', None)
102101

103-
# pylint: disable=not-callable
104102
result = NotImplemented if raiser is None else raiser(-1)
105103
if result is not NotImplemented:
106104
return result
@@ -121,6 +119,3 @@ def inverse(val: Any, default: Any = RaiseTypeErrorIfNotProvided) -> Any:
121119
"It has no __pow__ method (or the method returned NotImplemented) "
122120
"and it isn't an iterable of invertible objects."
123121
)
124-
125-
126-
# pylint: enable=function-redefined

cirq-core/cirq/protocols/json_serialization.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,6 @@ def obj_to_dict_helper(obj: Any, attribute_names: Iterable[str]) -> dict[str, An
155155
return d
156156

157157

158-
# pylint: enable=redefined-builtin
159158
def dataclass_json_dict(obj: Any) -> dict[str, Any]:
160159
"""Return a dictionary suitable for `_json_dict_` from a dataclass.
161160
@@ -460,7 +459,6 @@ def cirq_type_from_json(type_str: str, resolvers: Sequence[JsonResolver] | None
460459
raise ValueError(f"Type {type_str} maps to a factory method instead of a type.")
461460

462461

463-
# pylint: disable=function-redefined
464462
@overload
465463
def to_json(
466464
obj: Any, file_or_fn: IO | pathlib.Path | str, *, indent=2, separators=None, cls=CirqEncoder
@@ -517,7 +515,6 @@ def to_json(
517515
return None
518516

519517

520-
# pylint: enable=function-redefined
521518
def read_json(
522519
file_or_fn: None | IO | pathlib.Path | str = None,
523520
*,

cirq-core/cirq/protocols/mul_protocol.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,3 @@ def mul(lhs: Any, rhs: Any, default: Any = RaiseTypeErrorIfNotProvided) -> Any:
7171
if default is not RaiseTypeErrorIfNotProvided:
7272
return default
7373
raise TypeError(f"unsupported operand type(s) for *: '{type(lhs)}' and '{type(rhs)}'")
74-
75-
76-
# pylint: enable=function-redefined, redefined-builtin

cirq-core/cirq/protocols/pow_protocol.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
TDefault = TypeVar('TDefault')
2727

2828

29-
# pylint: disable=function-redefined, redefined-builtin
29+
# pylint: disable=redefined-builtin
3030
@overload
3131
def pow(val: cirq.Gate, exponent: Any) -> cirq.Gate:
3232
pass
@@ -57,7 +57,7 @@ def pow(val: Any, exponent: Any, default: TDefault) -> Any:
5757
pass
5858

5959

60-
# pylint: enable=function-redefined
60+
# pylint: enable=redefined-builtin
6161

6262

6363
def pow(val: Any, exponent: Any, default: Any = RaiseTypeErrorIfNotProvided) -> Any:
@@ -96,6 +96,3 @@ def pow(val: Any, exponent: Any, default: Any = RaiseTypeErrorIfNotProvided) ->
9696
raise TypeError(
9797
f"object of type '{type(val)}' does have a __pow__ method, but it returned NotImplemented."
9898
)
99-
100-
101-
# pylint: enable=redefined-builtin

0 commit comments

Comments
 (0)