Skip to content

Commit 2f7b46c

Browse files
committed
Fix (new) formatting errors due to ruff update.
1 parent e537172 commit 2f7b46c

File tree

14 files changed

+21
-26
lines changed

14 files changed

+21
-26
lines changed

opensquirrel/ir.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ def __init__(self, *axis: AxisLike) -> None:
213213
214214
axis: An ``AxisLike`` to create the axis from.
215215
"""
216-
axis_to_parse = axis[0] if len(axis) == 1 else cast(AxisLike, axis)
216+
axis_to_parse = axis[0] if len(axis) == 1 else cast("AxisLike", axis)
217217
self._value = self.normalize(self.parse(axis_to_parse))
218218

219219
@property
@@ -281,7 +281,7 @@ def __getitem__(self, s: slice, /) -> list[np.float64]: ...
281281

282282
def __getitem__(self, index: int | slice, /) -> np.float64 | list[np.float64]:
283283
"""Get the item at `index`."""
284-
return cast(np.float64, self.value[index])
284+
return cast("np.float64", self.value[index])
285285

286286
def __len__(self) -> int:
287287
"""Length of the axis, which is always 3."""
@@ -706,7 +706,7 @@ def named_gate(gate_generator: Callable[..., ControlledGate]) -> Callable[..., C
706706

707707

708708
def named_gate(gate_generator: Callable[..., Gate]) -> Callable[..., Gate]:
709-
return cast(Callable[..., Gate], instruction_decorator(gate_generator))
709+
return cast("Callable[..., Gate]", instruction_decorator(gate_generator))
710710

711711

712712
@overload
@@ -730,7 +730,7 @@ def non_unitary(non_unitary_generator: Callable[..., Wait]) -> Callable[..., Wai
730730

731731

732732
def non_unitary(non_unitary_generator: Callable[..., NonUnitary]) -> Callable[..., NonUnitary]:
733-
return cast(Callable[..., NonUnitary], instruction_decorator(non_unitary_generator))
733+
return cast("Callable[..., NonUnitary]", instruction_decorator(non_unitary_generator))
734734

735735

736736
def compare_gates(g1: Gate, g2: Gate) -> bool:

opensquirrel/parser/libqasm/parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ def _check_analysis_result(result: Any) -> None:
174174
def _get_gate_f(instruction: cqasm.semantic.GateInstruction) -> Callable[..., Gate]:
175175
gate_name = instruction.gate.name
176176
if gate_name in ["inv", "pow", "ctrl"]:
177-
modified_gate_f = cast(Callable[..., BlochSphereRotation], Parser._get_gate_f(instruction.gate))
177+
modified_gate_f = cast("Callable[..., BlochSphereRotation]", Parser._get_gate_f(instruction.gate))
178178
if gate_name == "inv":
179179
return InverseGateModifier(modified_gate_f)
180180
if gate_name == "pow":

opensquirrel/passes/decomposer/aba_decomposer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def _set_a_b_c_axes_values(self, axis: AxisLike) -> tuple[Any, Any, Any]:
5252
Returns:
5353
A triplet (a, b, c) where a, b, and c are the values of x, y, and z reordered.
5454
"""
55-
_axis = Axis(axis)
55+
_axis = Axis(axis) # noqa: RUF052
5656
return _axis[self.index_a], _axis[self.index_b], _axis[self._find_unused_index()]
5757

5858
@staticmethod

opensquirrel/passes/exporter/cqasmv1_exporter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def _dump_barrier_group(indices: list[int]) -> str:
9191

9292

9393
def _get_barrier_index(line: str) -> int:
94-
barrier_index_match = re.search("\d+", line)
94+
barrier_index_match = re.search(r"\d+", line)
9595
if not barrier_index_match:
9696
msg = "expecting a barrier index but found none"
9797
raise CqasmV1ExporterParseError(msg)

opensquirrel/passes/merger/general_merger.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ def can_move_before(statement: Statement, statement_group: list[Statement]) -> b
127127
first_statement_from_group = statement_group[0]
128128
if not isinstance(first_statement_from_group, Barrier):
129129
return False
130-
instruction = cast(Instruction, statement)
131-
return can_move_statement_before_barrier(instruction, cast(list[Instruction], statement_group))
130+
instruction = cast("Instruction", statement)
131+
return can_move_statement_before_barrier(instruction, cast("list[Instruction]", statement_group))
132132

133133

134134
def group_linked_barriers(statements: list[Statement]) -> list[list[Statement]]:

opensquirrel/passes/merger/single_qubit_gates_merger.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def merge(self, ir: IR, qubit_register_size: int) -> None:
2222
statement = ir.statements[statement_index]
2323

2424
# Accumulate consecutive Bloch sphere rotations
25-
instruction: Instruction = cast(Instruction, statement)
25+
instruction: Instruction = cast("Instruction", statement)
2626
if isinstance(instruction, BlochSphereRotation):
2727
already_accumulated = accumulators_per_qubit[instruction.qubit]
2828
composed = compose_bloch_sphere_rotations(already_accumulated, instruction)

opensquirrel/passes/router/routing_checker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def __init__(self, connectivity: dict[str, list[int]]) -> None:
1111
def route(self, ir: IR) -> None:
1212
non_executable_interactions = []
1313
for statement in ir.statements:
14-
instruction: Instruction = cast(Instruction, statement)
14+
instruction: Instruction = cast("Instruction", statement)
1515
args = instruction.arguments
1616
if args and len(args) > 1 and all(isinstance(arg, Qubit) for arg in args):
1717
qubit_args = [arg for arg in args if isinstance(arg, Qubit)]

poetry.lock

Lines changed: 2 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ numpy = [
3535
]
3636
libqasm = "0.6.9"
3737
networkx = "^3.0.0"
38+
tox = "^4.24.1"
3839

3940
[tool.poetry.group.dev.dependencies]
4041
coverage = {extras = ["toml"], version = "^7.3.2"}
@@ -156,8 +157,6 @@ select = [
156157
]
157158
ignore = [
158159
"A005", # module shadowing a Python builtin module
159-
"ANN101", # self should not be typed
160-
"ANN102", # cls should not be typed
161160
"ANN401", # typing.Any can be useful (for example in __eq__)
162161
"COM812", # Conflicts with ruff format
163162
"ISC001", # Possible conflicts with ruff format

test/parser/libqasm/test_libqasm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def test_sgmq() -> None:
5959
def test_error() -> None:
6060
with pytest.raises(
6161
IOError,
62-
match="Error at <unknown file name>:1:30..31: failed to resolve variable 'q'",
62+
match=r"Error at <unknown file name>:1:30..31: failed to resolve variable 'q'",
6363
):
6464
Parser().circuit_from_string("version 3.0; qubit[20] qu; H q[5]")
6565

test/router/test_routing_checker.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,7 @@ def test_routing_checker_possible_1to1_mapping(router: RoutingChecker, circuit1:
4848

4949

5050
def test_routing_checker_impossible_1to1_mapping(router: RoutingChecker, circuit2: Circuit) -> None:
51-
with pytest.raises(ValueError, match="The following qubit interactions in the circuit prevent a 1-to-1 mapping:.*"):
51+
with pytest.raises(
52+
ValueError, match=r"The following qubit interactions in the circuit prevent a 1-to-1 mapping:.*"
53+
):
5254
router.route(circuit2.ir)

test/test_circuit_builder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def test_unknown_instruction(self) -> None:
7171
def test_wrong_number_of_arguments(self) -> None:
7272
builder = CircuitBuilder(3)
7373

74-
with pytest.raises(TypeError, match=".* takes 1 positional argument but 2 were given"):
74+
with pytest.raises(TypeError, match=r".* takes 1 positional argument but 2 were given"):
7575
builder.H(0, 1)
7676

7777
def test_decoupling_circuit_and_builder(self) -> None:

test/test_integration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ def test_hectoqubit_backend_allxy() -> None:
267267
if importlib.util.find_spec("quantify_scheduler") is None:
268268
with pytest.raises(
269269
Exception,
270-
match="quantify-scheduler is not installed, or cannot be installed on " "your system",
270+
match="quantify-scheduler is not installed, or cannot be installed on your system",
271271
):
272272
qc.export(fmt=ExportFormat.QUANTIFY_SCHEDULER)
273273
else:

test/test_ir.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ def test_array_like(self) -> None:
325325
)
326326

327327
def test_incorrect_array(self) -> None:
328-
with pytest.raises(ValueError, match=".* inhomogeneous shape after .*") as e_info:
328+
with pytest.raises(ValueError, match=r".* inhomogeneous shape after .*") as e_info:
329329
MatrixGate([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 0, 1], [0, 0, 0]], [0, 1])
330330
assert "setting an array element with a sequence." in str(e_info.value)
331331

0 commit comments

Comments
 (0)