Skip to content

Commit 6bb6661

Browse files
authored
ruff - enable and fix rules F401, F601 (#7413)
- enable and fix F601 - multi-value-repeated-key-literal - enable and fix F401 - unused-import No change in the effective code. Partially implements #7371
1 parent 4a128dc commit 6bb6661

File tree

27 files changed

+38
-40
lines changed

27 files changed

+38
-40
lines changed

cirq-core/cirq/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
"""Cirq is a framework for creating, editing, and invoking quantum circuits."""
1616

17+
# ruff: noqa: F401
18+
1719
from cirq import _import
1820

1921
from cirq._compat import __cirq_debug__ as __cirq_debug__, with_debug as with_debug

cirq-core/cirq/_compat_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -813,7 +813,7 @@ def _test_broken_module_1_inner():
813813
DeprecatedModuleImportError, match="missing_module cannot be imported. The typical reasons"
814814
):
815815
# pylint: disable=unused-import
816-
import cirq.testing._compat_test_data.broken_ref as br # type: ignore
816+
import cirq.testing._compat_test_data.broken_ref as br # type: ignore # noqa: F401
817817

818818

819819
def _test_broken_module_2_inner():

cirq-core/cirq/contrib/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
this package.
1919
"""
2020

21-
from cirq.contrib import acquaintance
22-
from cirq.contrib import graph_device
23-
from cirq.contrib import quirk
21+
from cirq.contrib import acquaintance # noqa: F401
22+
from cirq.contrib import graph_device # noqa: F401
23+
from cirq.contrib import quirk # noqa: F401
2424
from cirq.contrib.qcircuit import circuit_to_latex_using_qcircuit as circuit_to_latex_using_qcircuit
25-
from cirq.contrib import json
25+
from cirq.contrib import json # noqa: F401
2626
from cirq.contrib.circuitdag import CircuitDag as CircuitDag, Unique as Unique

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,4 @@
7979
random_topological_sort as random_topological_sort,
8080
)
8181

82-
from cirq.contrib.acquaintance import testing
82+
from cirq.contrib.acquaintance import testing # noqa: F401

cirq-core/cirq/contrib/quimb/Cirq-to-Tensor-Networks.ipynb

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,12 @@
88
"source": [
99
"import importlib.util\n",
1010
"\n",
11-
"try:\n",
12-
" import cirq\n",
13-
"except ImportError:\n",
11+
"if importlib.util.find_spec('cirq') is None:\n",
1412
" print(\"installing cirq...\")\n",
1513
" !pip install --quiet cirq\n",
1614
" print(\"installed cirq.\")\n",
1715
"\n",
18-
"try:\n",
19-
" import quimb\n",
20-
"except ImportError:\n",
16+
"if importlib.util.find_spec('quimb') is None:\n",
2117
" print(\"installing cirq-core[contrib]...\")\n",
2218
" !pip install --quiet 'cirq-core[contrib]'\n",
2319
" print(\"installed cirq-core[contrib].\")"
@@ -58,7 +54,6 @@
5854
"outputs": [],
5955
"source": [
6056
"import cirq.contrib.quimb as ccq\n",
61-
"import quimb\n",
6257
"import quimb.tensor as qtn"
6358
]
6459
},

cirq-core/cirq/contrib/quimb/Contract-a-Grid-Circuit.ipynb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
"metadata": {},
1414
"outputs": [],
1515
"source": [
16-
"import importlib.util\n",
17-
"\n",
1816
"try:\n",
1917
" import cirq\n",
2018
"except ImportError:\n",

cirq-core/cirq/experiments/benchmarking/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@
1414

1515
"""Tools for branchmarking NISQ circuits."""
1616

17-
from cirq.experiments.benchmarking.parallel_xeb import parallel_two_qubit_xeb
17+
from cirq.experiments.benchmarking.parallel_xeb import parallel_two_qubit_xeb # noqa: F401

cirq-core/cirq/interop/quirk/cells/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,4 @@
3737
)
3838

3939
import cirq.interop.quirk.cells.swap_cell
40-
import cirq.interop.quirk.cells.control_cells
40+
import cirq.interop.quirk.cells.control_cells # noqa: F401

cirq-core/cirq/testing/_compat_test_data/module_a/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# pylint: disable=wrong-or-nonexistent-copyright-notice
2+
# ruff: noqa: F401
23
"""module_a for module deprecation tests"""
34

45
import logging
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# pylint: disable=wrong-or-nonexistent-copyright-notice
2+
# ruff: noqa: F401
23
from cirq.testing._compat_test_data.module_a.module_b import module_c
34

45
MODULE_B_ATTRIBUTE = "module_b"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
# pylint: disable=wrong-or-nonexistent-copyright-notice
2+
# ruff: noqa: F401
23
from cirq.testing._compat_test_data.module_a.sub.subsub import dupe

cirq-core/cirq/testing/consistent_qasm_test.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
from __future__ import annotations
1616

17+
import importlib.util
1718
import warnings
1819

1920
import numpy as np
@@ -53,9 +54,7 @@ def _qasm_(self, args: cirq.QasmArgs, qubits: tuple[cirq.Qid, ...]):
5354

5455

5556
def test_assert_qasm_is_consistent_with_unitary() -> None:
56-
try:
57-
import qiskit as _
58-
except ImportError: # pragma: no cover
57+
if importlib.util.find_spec('qiskit') is None: # pragma: no cover
5958
warnings.warn(
6059
"Skipped test_assert_qasm_is_consistent_with_unitary "
6160
"because qiskit isn't installed to verify against."

cirq-core/cirq/transformers/gauge_compiling/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,6 @@
3939
SqrtISWAPGaugeTransformer as SqrtISWAPGaugeTransformer,
4040
)
4141

42-
from cirq.transformers.gauge_compiling.cphase_gauge import CPhaseGaugeTransformer
42+
from cirq.transformers.gauge_compiling.cphase_gauge import (
43+
CPhaseGaugeTransformer as CPhaseGaugeTransformer,
44+
)

cirq-google/cirq_google/__init__.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414

1515
"""Classes for working with Google's Quantum Engine API."""
1616

17-
import sys
18-
from cirq_google import api
17+
from cirq_google import api # noqa: F401
1918

2019
from cirq_google._version import __version__ as __version__
2120

@@ -107,9 +106,9 @@
107106
SimulatedProcessorWithLocalDeviceRecord as SimulatedProcessorWithLocalDeviceRecord,
108107
)
109108

110-
from cirq_google import study
109+
from cirq_google import study # noqa: F401
111110

112-
from cirq_google import experimental
111+
from cirq_google import experimental # noqa: F401
113112

114113

115114
# Register cirq_google's public classes for JSON serialization.

cirq-google/cirq_google/api/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313
# limitations under the License.
1414
"""Helpers for converting to/from api data formats."""
1515

16-
from cirq_google.api import v2
16+
from cirq_google.api import v2 # noqa: F401

cirq-google/cirq_google/api/v1/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# limitations under the License.
1414
"""Data format v1 for google api."""
1515

16-
from cirq_google.api.v1 import operations_pb2, params_pb2, program_pb2
16+
from cirq_google.api.v1 import operations_pb2, params_pb2, program_pb2 # noqa: F401
1717

1818
from cirq_google.api.v1.params import (
1919
sweep_from_proto as sweep_from_proto,

cirq-google/cirq_google/api/v1/proto_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@
1818

1919
from __future__ import annotations
2020

21-
from cirq_google.api.v1 import operations_pb2, params_pb2, program_pb2
21+
from cirq_google.api.v1 import operations_pb2, params_pb2, program_pb2 # noqa: F401
2222

2323
# pylint: enable=unused-import

cirq-google/cirq_google/api/v2/__init__.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,13 @@
1313
# limitations under the License.
1414
"""Data format v2 for google api."""
1515

16-
from cirq_google.api.v2 import device_pb2, metrics_pb2, program_pb2, result_pb2, run_context_pb2
16+
from cirq_google.api.v2 import (
17+
device_pb2, # noqa: F401
18+
metrics_pb2, # noqa: F401
19+
program_pb2, # noqa: F401
20+
result_pb2, # noqa: F401
21+
run_context_pb2, # noqa: F401
22+
)
1723

1824
from cirq_google.api.v2.program import (
1925
grid_qubit_from_proto_id as grid_qubit_from_proto_id,

cirq-google/cirq_google/api/v2/proto_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@
1818

1919
from __future__ import annotations
2020

21-
from cirq_google.api.v2 import metrics_pb2, program_pb2, result_pb2, run_context_pb2
21+
from cirq_google.api.v2 import metrics_pb2, program_pb2, result_pb2, run_context_pb2 # noqa: F401
2222

2323
# pylint: enable=unused-import

cirq-google/cirq_google/engine/abstract_processor.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
import cirq_google.engine.abstract_engine as abstract_engine
3636
import cirq_google.engine.abstract_job as abstract_job
3737
import cirq_google.engine.calibration as calibration
38-
import cirq_google.serialization.serializer as serializer
3938

4039

4140
class AbstractProcessor(abc.ABC):

cirq-google/cirq_google/engine/simulated_local_program.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
from cirq_google.engine.local_simulation_type import LocalSimulationType
2121

2222
if TYPE_CHECKING:
23-
from cirq_google.engine.abstract_engine import AbstractEngine
24-
from cirq_google.engine.abstract_job import AbstractJob
2523
from cirq_google.engine.simulated_local_processor import SimulatedLocalProcessor
2624

2725

cirq-ionq/cirq_ionq/service_test.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ def test_service_run(target, expected_results):
4040
'target': target,
4141
'metadata': {'shots': '4', 'measurement0': f'a{chr(31)}0'},
4242
'qubits': '1',
43-
'status': 'completed',
4443
}
4544
mock_client.get_results.return_value = {'0': '0.25', '1': '0.75'}
4645
service._client = mock_client
@@ -86,7 +85,6 @@ def test_service_run_batch(target, expected_results1, expected_results2):
8685
'qubit_numbers': '[1, 1]',
8786
},
8887
'qubits': '1',
89-
'status': 'completed',
9088
}
9189
mock_client.get_results.return_value = {
9290
"xxx": {'0': '0.25', '1': '0.75'},

cirq-rigetti/cirq_rigetti/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
# ruff: noqa: F401
16+
1517
from cirq_rigetti._version import __version__ as __version__
1618

1719
from cirq_rigetti.sampler import (

cirq-web/circuit_example.ipynb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@
7474
"qubits = [cirq.GridQubit(x, y) for x in range(10) for y in range(10)]\n",
7575
"\n",
7676
"import cirq.testing\n",
77-
"from cirq.protocols import circuit_diagram_info\n",
7877
"\n",
7978
"circuit = cirq.testing.random_circuit(cirq.GridQubit.square(10), n_moments=5, op_density=0.7)"
8079
]

examples/advanced/quantum_volume.ipynb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
"outputs": [],
3232
"source": [
3333
"import cirq\n",
34-
"import cirq_google\n",
3534
"\n",
3635
"qubits = cirq.GridQubit.rect(3, 2)\n",
3736
"qubits"

examples/advanced/quantum_volume_routing.ipynb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
"outputs": [],
3232
"source": [
3333
"import cirq\n",
34-
"import cirq_google\n",
3534
"\n",
3635
"# Configuration parameters. Feel free to mess with these!\n",
3736
"num_circuits = 10\n",

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ extend-exclude = ["*_pb2.py*"]
5757
[tool.ruff.lint]
5858
select = [
5959
# "ANN201", # missing-return-type-undocumented-public-function
60-
# "F401", # unused-import
61-
# "F601", # multi-value-repeated-key-literal
60+
"F401", # unused-import
61+
"F601", # multi-value-repeated-key-literal
6262
"F821", # undefined-name
6363
"RUF100", # unused-noqa
6464
"TC001", # typing-only-first-party-import

0 commit comments

Comments
 (0)