Skip to content

Commit

Permalink
pylint - enforce singleton-comparison check (quantumlib#4625)
Browse files Browse the repository at this point in the history
Correct few lint issues that show after enabling singleton-comparison check.
  • Loading branch information
pavoljuhas authored and rht committed May 1, 2023
1 parent 4bd39e6 commit a7e0929
Show file tree
Hide file tree
Showing 14 changed files with 18 additions and 19 deletions.
4 changes: 2 additions & 2 deletions cirq-core/cirq/_compat_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ def _import_parent_use_constant_from_deprecated_module_attribute():
# the parent should have fake_a set on it as an attribute - just like
# a regular module import (e.g. cirq.ops)
# should have a DUPE_CONSTANT as its imported from the dupe submodule
assert cirq.testing._compat_test_data.fake_a.DUPE_CONSTANT == False
assert cirq.testing._compat_test_data.fake_a.DUPE_CONSTANT is False

assert 'module_a for module deprecation tests' in cirq.testing._compat_test_data.fake_a.__doc__
assert 'Test module for deprecation testing' in cirq.testing._compat_test_data.__doc__
Expand All @@ -467,7 +467,7 @@ def _import_deprecated_sub_use_constant():
import cirq.testing._compat_test_data.fake_a.dupe # type: ignore

# should have a DUPE_CONSTANT as its defined on it, set to False
assert cirq.testing._compat_test_data.fake_a.dupe.DUPE_CONSTANT == False
assert cirq.testing._compat_test_data.fake_a.dupe.DUPE_CONSTANT is False


def _import_deprecated_same_name_in_earlier_subtree():
Expand Down
2 changes: 1 addition & 1 deletion cirq-core/cirq/circuits/qasm_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def _generate_qubit_ids(self) -> Dict['cirq.Qid', str]:

def is_valid_qasm_id(self, id_str: str) -> bool:
"""Test if id_str is a valid id in QASM grammar."""
return self.valid_id_re.match(id_str) != None
return self.valid_id_re.match(id_str) is not None

def save(self, path: Union[str, bytes, int]) -> None:
"""Write QASM output to a file specified by path."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,5 @@ def test_regular_uniform_undirected_linear_device(arity):
assert device.qubits == tuple(cirq.LineQubit.range(n_qubits))
assert len(device.edges) == n_qubits - arity + 1
for edge, label in device.labelled_edges.items():
assert label == None
assert label is None
assert len(edge) == arity
2 changes: 1 addition & 1 deletion cirq-core/cirq/ion/ion_gates_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,4 @@ def custom_resolver(cirq_type: str) -> Union[Callable[..., cirq.Gate], None]:
assert cirq.read_json(
json_text=cirq.to_json(cirq.ms(np.pi / 2)), resolvers=[custom_resolver]
) == cirq.ms(np.pi / 2)
assert custom_resolver('X') == None
assert custom_resolver('X') is None
2 changes: 1 addition & 1 deletion cirq-core/cirq/ops/measurement_gate_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def test_qudit_measure_quil():
cirq.measure(q0, key='a'),
formatter=cirq.QuilFormatter(qubit_id_map=qubit_id_map, measurement_id_map={}),
)
== None
is None
)


Expand Down
5 changes: 2 additions & 3 deletions cirq-core/cirq/protocols/apply_channel_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,8 @@ def apply_channel(
)

# Check if the specialized method is present.
func = getattr(val, '_apply_channel_', None)
if func is not None:
result = func(args)
if hasattr(val, '_apply_channel_'):
result = val._apply_channel_(args)
if result is not NotImplemented and result is not None:

def err_str(buf_num_str):
Expand Down
5 changes: 2 additions & 3 deletions cirq-core/cirq/protocols/apply_mixture_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,8 @@ def apply_mixture(
val, args, is_density_matrix = _validate_input(val, args)

# Check if the specialized method is present. (STEP A)
func = getattr(val, '_apply_mixture_', None)
if func is not None:
result = func(args)
if hasattr(val, '_apply_mixture_'):
result = val._apply_mixture_(args)
if result is not NotImplemented and result is not None:

def err_str(buf_num_str):
Expand Down
4 changes: 2 additions & 2 deletions cirq-core/cirq/protocols/phase_protocol_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ def _phase_by_(self, phase_turns, qubit_on):
_ = cirq.phase_by(rin, 1, 0)

# With default
assert cirq.phase_by(n, 1, 0, default=None) == None
assert cirq.phase_by(rin, 1, 0, default=None) == None
assert cirq.phase_by(n, 1, 0, default=None) is None
assert cirq.phase_by(rin, 1, 0, default=None) is None

test = PhaseIsAddition(3)
assert test.phase == [0, 0, 0]
Expand Down
2 changes: 1 addition & 1 deletion cirq-core/cirq/qis/clifford_tableau_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ def test_validate_tableau():
assert t._validate()

t.xs = np.zeros((4, 2))
assert t._validate() == False
assert not t._validate()


def test_rowsum():
Expand Down
2 changes: 1 addition & 1 deletion cirq-google/cirq_google/engine/engine_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -868,7 +868,7 @@ def update_reservation(
if end:
reservation.end_time.seconds = int(end.timestamp())
paths.append('end_time')
if whitelisted_users != None:
if whitelisted_users is not None:
reservation.whitelisted_users.extend(whitelisted_users)
paths.append('whitelisted_users')

Expand Down
2 changes: 1 addition & 1 deletion cirq-google/cirq_google/engine/engine_client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1028,7 +1028,7 @@ def test_get_reservation_not_found(client_constructor):

client = EngineClient()
assert (client.get_reservation('proj', 'processor0',
'papar-party-44') == None)
'papar-party-44') is None)
kwargs = grpc_client.get_quantum_reservation.call_args[1]
assert kwargs == {
'name': name,
Expand Down
2 changes: 1 addition & 1 deletion cirq-ionq/cirq_ionq/ionq_client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def test_ionq_client_attributes():
}
assert client.default_target == 'qpu'
assert client.max_retry_seconds == 10
assert client.verbose == True
assert client.verbose is True


@mock.patch('requests.post')
Expand Down
1 change: 1 addition & 0 deletions dev_tools/conf/.pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ enable=
return-in-init,
return-outside-function,
simplifiable-if-statement,
singleton-comparison,
syntax-error,
too-many-function-args,
trailing-whitespace,
Expand Down
2 changes: 1 addition & 1 deletion dev_tools/snippets_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ def print_capture(*values, sep=' '):
assert_expected_lines_present_in_order(expected_outputs, output_lines)
except AssertionError as ex:
new_msg = ex.args[0] + '\n\nIn snippet{}:\n{}'.format(
"" if line_number == None else " (line {})".format(line_number), _indent([snippet])
"" if line_number is None else " (line {})".format(line_number), _indent([snippet])
)
ex.args = (new_msg,) + tuple(ex.args[1:])
raise
Expand Down

0 comments on commit a7e0929

Please sign in to comment.