diff --git a/cirq-core/cirq/_compat_test.py b/cirq-core/cirq/_compat_test.py index 873b43f6b54..b0c84bc7e9f 100644 --- a/cirq-core/cirq/_compat_test.py +++ b/cirq-core/cirq/_compat_test.py @@ -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__ @@ -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(): diff --git a/cirq-core/cirq/circuits/qasm_output.py b/cirq-core/cirq/circuits/qasm_output.py index 4c025c36fc2..eb3ca16528a 100644 --- a/cirq-core/cirq/circuits/qasm_output.py +++ b/cirq-core/cirq/circuits/qasm_output.py @@ -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.""" diff --git a/cirq-core/cirq/contrib/graph_device/uniform_graph_device_test.py b/cirq-core/cirq/contrib/graph_device/uniform_graph_device_test.py index 386eea68837..5a63c490057 100644 --- a/cirq-core/cirq/contrib/graph_device/uniform_graph_device_test.py +++ b/cirq-core/cirq/contrib/graph_device/uniform_graph_device_test.py @@ -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 diff --git a/cirq-core/cirq/ion/ion_gates_test.py b/cirq-core/cirq/ion/ion_gates_test.py index 18a69c31850..e94c9e9255e 100644 --- a/cirq-core/cirq/ion/ion_gates_test.py +++ b/cirq-core/cirq/ion/ion_gates_test.py @@ -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 diff --git a/cirq-core/cirq/ops/measurement_gate_test.py b/cirq-core/cirq/ops/measurement_gate_test.py index 70f49f2b081..4aa6e5322e5 100644 --- a/cirq-core/cirq/ops/measurement_gate_test.py +++ b/cirq-core/cirq/ops/measurement_gate_test.py @@ -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 ) diff --git a/cirq-core/cirq/protocols/apply_channel_protocol.py b/cirq-core/cirq/protocols/apply_channel_protocol.py index caee1bebaa6..88c3570f135 100644 --- a/cirq-core/cirq/protocols/apply_channel_protocol.py +++ b/cirq-core/cirq/protocols/apply_channel_protocol.py @@ -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): diff --git a/cirq-core/cirq/protocols/apply_mixture_protocol.py b/cirq-core/cirq/protocols/apply_mixture_protocol.py index 78fb89029e3..5db8744acac 100644 --- a/cirq-core/cirq/protocols/apply_mixture_protocol.py +++ b/cirq-core/cirq/protocols/apply_mixture_protocol.py @@ -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): diff --git a/cirq-core/cirq/protocols/phase_protocol_test.py b/cirq-core/cirq/protocols/phase_protocol_test.py index 31ecd2feacc..df8e52a28ad 100644 --- a/cirq-core/cirq/protocols/phase_protocol_test.py +++ b/cirq-core/cirq/protocols/phase_protocol_test.py @@ -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] diff --git a/cirq-core/cirq/qis/clifford_tableau_test.py b/cirq-core/cirq/qis/clifford_tableau_test.py index 54d6b16766a..b8dd940e663 100644 --- a/cirq-core/cirq/qis/clifford_tableau_test.py +++ b/cirq-core/cirq/qis/clifford_tableau_test.py @@ -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(): diff --git a/cirq-google/cirq_google/engine/engine_client.py b/cirq-google/cirq_google/engine/engine_client.py index 457792ee7e0..7e0ac00296e 100644 --- a/cirq-google/cirq_google/engine/engine_client.py +++ b/cirq-google/cirq_google/engine/engine_client.py @@ -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') diff --git a/cirq-google/cirq_google/engine/engine_client_test.py b/cirq-google/cirq_google/engine/engine_client_test.py index b3494ed6401..ff91b5002db 100644 --- a/cirq-google/cirq_google/engine/engine_client_test.py +++ b/cirq-google/cirq_google/engine/engine_client_test.py @@ -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, diff --git a/cirq-ionq/cirq_ionq/ionq_client_test.py b/cirq-ionq/cirq_ionq/ionq_client_test.py index 96e318e4f05..f4a233f75aa 100644 --- a/cirq-ionq/cirq_ionq/ionq_client_test.py +++ b/cirq-ionq/cirq_ionq/ionq_client_test.py @@ -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') diff --git a/dev_tools/conf/.pylintrc b/dev_tools/conf/.pylintrc index 48d8b10c73b..6754142ca4a 100644 --- a/dev_tools/conf/.pylintrc +++ b/dev_tools/conf/.pylintrc @@ -40,6 +40,7 @@ enable= return-in-init, return-outside-function, simplifiable-if-statement, + singleton-comparison, syntax-error, too-many-function-args, trailing-whitespace, diff --git a/dev_tools/snippets_test.py b/dev_tools/snippets_test.py index fecbad6f0bc..476c5cd2749 100644 --- a/dev_tools/snippets_test.py +++ b/dev_tools/snippets_test.py @@ -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