Skip to content

Commit 12eab31

Browse files
authored
pylint - sync with rules used in internal codes (#7387)
Activate pylint rules used in pyle and fix flagged issues. Added pylint rules: - abstract-class-instantiated - assignment-from-no-return - bad-chained-comparison - bad-mcs-classmethod-argument - bad-mcs-method-argument - deprecated-decorator - method-hidden - raising-bad-type - raising-format-tuple - redefined-slots-in-subclass - self-cls-assignment - shadowed-import - simplifiable-condition - unneeded-not - use-maxsplit-arg - using-constant-test Related to #7371
1 parent 8b02d60 commit 12eab31

File tree

12 files changed

+40
-24
lines changed

12 files changed

+40
-24
lines changed

cirq-core/cirq/ops/control_values_test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,14 +239,14 @@ def test_sum_of_products_repr(data):
239239
def test_sum_of_products_validate():
240240
control_val = cirq.SumOfProducts(((1, 2), (0, 1)))
241241

242-
_ = control_val.validate([2, 3])
242+
control_val.validate([2, 3])
243243

244244
with pytest.raises(ValueError):
245-
_ = control_val.validate([2, 2])
245+
control_val.validate([2, 2])
246246

247247
# number of qubits != number of control values.
248248
with pytest.raises(ValueError):
249-
_ = control_val.validate([2])
249+
control_val.validate([2])
250250

251251

252252
@pytest.mark.parametrize('data', [((1,),), ((0, 1),), ((0, 0), (0, 1), (1, 0))])

cirq-core/cirq/ops/pauli_gates_test.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ def test_relative_index_consistency() -> None:
116116

117117

118118
def test_gt() -> None:
119+
# pylint: disable=unnecessary-negation
119120
assert not cirq.X > cirq.X
120121
assert not cirq.X > cirq.Y
121122
assert cirq.X > cirq.Z
@@ -133,6 +134,7 @@ def test_gt_other_type() -> None:
133134

134135

135136
def test_lt() -> None:
137+
# pylint: disable=unnecessary-negation
136138
assert not cirq.X < cirq.X
137139
assert cirq.X < cirq.Y
138140
assert not cirq.X < cirq.Z

cirq-core/cirq/ops/raw_types_test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ def test_wrapped_qid():
7979
'dimension': 3,
8080
}
8181

82+
# pylint: disable=unnecessary-negation
8283
assert not ValidQubit('zz') == 4
8384
assert ValidQubit('zz') != 4
8485
assert ValidQubit('zz') > ValidQubit('aa')

cirq-core/cirq/ops/state_preparation_channel_test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ def test_gate_error_handling() -> None:
124124

125125

126126
def test_equality_of_gates() -> None:
127+
# pylint: disable=unnecessary-negation
127128
state = np.array([1, 0, 0, 0], dtype=np.complex64)
128129
gate_1 = cirq.StatePreparationChannel(state)
129130
gate_2 = cirq.StatePreparationChannel(state)

cirq-core/cirq/protocols/qasm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def __init__(
6464
def _format_number(self, value) -> str:
6565
"""OpenQASM 2.0 does not support '1e-5' and wants '1.0e-5'"""
6666
s = f'{value}'
67-
if 'e' in s and not '.' in s:
67+
if 'e' in s and '.' not in s:
6868
return s.replace('e', '.0e')
6969
return s
7070

cirq-core/cirq/sim/clifford/clifford_simulator_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ def test_valid_apply_measurement():
570570
q0 = cirq.LineQubit(0)
571571
state = cirq.CliffordState(qubit_map={q0: 0}, initial_state=1)
572572
measurements = {}
573-
_ = state.apply_measurement(
573+
state.apply_measurement(
574574
cirq.measure(q0), measurements, np.random.RandomState(), collapse_state_vector=False
575575
)
576576
assert measurements == {'q(0)': [1]}

cirq-core/cirq/sim/simulator_test.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from __future__ import annotations
1818

1919
import abc
20-
from typing import Any, Generic, Sequence
20+
from typing import Any, Generic, Iterator, Sequence
2121
from unittest import mock
2222

2323
import duet
@@ -73,6 +73,11 @@ class SimulatesIntermediateStateImpl(
7373
):
7474
"""A SimulatesIntermediateState that uses the default SimulationTrialResult type."""
7575

76+
def _base_iterator(
77+
self, circuit: cirq.AbstractCircuit, qubits: tuple[cirq.Qid, ...], initial_state: Any
78+
) -> Iterator[TStepResult]:
79+
raise NotImplementedError
80+
7681
def _create_simulator_trial_result(
7782
self,
7883
params: study.ParamResolver,

cirq-core/cirq/value/abc_alt.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ class ABCMetaImplementAnyOneOf(abc.ABCMeta):
8282
`@alternative(...)` may be used.
8383
"""
8484

85-
def __new__(mcls, name, bases, namespace, **kwargs):
86-
cls = super().__new__(mcls, name, bases, namespace, **kwargs)
85+
def __new__(mcs, name, bases, namespace, **kwargs):
86+
cls = super().__new__(mcs, name, bases, namespace, **kwargs)
8787
implemented_by = {}
8888

8989
def has_some_implementation(name: str) -> bool:

cirq-core/cirq/value/linear_dict_test.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def test_empty_init():
2929

3030
sym = sympy.Symbol('sym')
3131
expr = sym * -(2 + 3j)
32-
symval = expr.subs({'sym': 5})
32+
symval = expr.subs({'sym': 5}) # pylint: disable=assignment-from-no-return
3333
symvalresolved = -10 - 15j
3434

3535

@@ -433,6 +433,7 @@ def test_bool(terms, bool_value):
433433
),
434434
)
435435
def test_equal(terms_1, terms_2):
436+
# pylint: disable=unnecessary-negation
436437
linear_dict_1 = cirq.LinearDict(terms_1)
437438
linear_dict_2 = cirq.LinearDict(terms_2)
438439
assert linear_dict_1 == linear_dict_2
@@ -452,6 +453,7 @@ def test_equal(terms_1, terms_2):
452453
),
453454
)
454455
def test_unequal(terms_1, terms_2):
456+
# pylint: disable=unnecessary-negation
455457
linear_dict_1 = cirq.LinearDict(terms_1)
456458
linear_dict_2 = cirq.LinearDict(terms_2)
457459
assert linear_dict_1 != linear_dict_2

cirq-core/cirq/value/measurement_key_test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ def test_with_measurement_key_mapping():
103103

104104

105105
def test_compare():
106+
# pylint: disable=unnecessary-negation
106107
assert cirq.MeasurementKey('a') < cirq.MeasurementKey('b')
107108
assert cirq.MeasurementKey('a') <= cirq.MeasurementKey('b')
108109
assert cirq.MeasurementKey('a') <= cirq.MeasurementKey('a')

0 commit comments

Comments
 (0)