Skip to content

Commit a30e7e8

Browse files
committed
Enable the ruff rule ensuring explicit strictness for zips
1 parent 80d6640 commit a30e7e8

File tree

5 files changed

+16
-6
lines changed

5 files changed

+16
-6
lines changed

pyproject.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,12 @@ line-length = 88
125125
exclude = ["doc/", "pytensor/_version.py"]
126126

127127
[tool.ruff.lint]
128-
select = ["C", "E", "F", "I", "UP", "W", "RUF", "PERF", "PTH", "ISC"]
128+
select = ["B905", "C", "E", "F", "I", "UP", "W", "RUF", "PERF", "PTH", "ISC"]
129129
ignore = ["C408", "C901", "E501", "E741", "RUF012", "PERF203", "ISC001"]
130+
unfixable = [
131+
# zip-strict: the auto-fix adds `strict=False` but we might want `strict=True` instead
132+
"B905",
133+
]
130134

131135

132136
[tool.ruff.lint.isort]

pytensor/link/c/op.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ def load_c_code(self, func_files: Iterable[Path]) -> None:
352352
"be used at the same time."
353353
)
354354

355-
for func_file, code in zip(func_files, self.func_codes):
355+
for func_file, code in zip(func_files, self.func_codes, strict=True):
356356
if self.backward_re.search(code):
357357
# This is backward compat code that will go away in a while
358358

pytensor/link/pytorch/dispatch/shape.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def shape_i(x):
3434
def pytorch_funcify_SpecifyShape(op, node, **kwargs):
3535
def specifyshape(x, *shape):
3636
assert x.ndim == len(shape)
37-
for actual, expected in zip(x.shape, shape):
37+
for actual, expected in zip(x.shape, shape, strict=True):
3838
if expected is None:
3939
continue
4040
if actual != expected:

pytensor/tensor/pad.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,9 @@ def _linear_ramp_pad(
263263
dtype=padded.dtype,
264264
axis=axis,
265265
)
266-
for end_value, edge, width in zip(end_value_pair, edge_pair, width_pair)
266+
for end_value, edge, width in zip(
267+
end_value_pair, edge_pair, width_pair, strict=True
268+
)
267269
)
268270

269271
# Reverse the direction of the ramp for the "right" side

pytensor/tensor/rewriting/ofg.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ def inline_ofg_expansion(fgraph, node):
1818
if not op.is_inline:
1919
return False
2020

21-
new_out = clone_replace(op.inner_outputs, dict(zip(op.inner_inputs, node.inputs)))
21+
new_out = clone_replace(
22+
op.inner_outputs, dict(zip(op.inner_inputs, node.inputs, strict=True))
23+
)
2224
copy_stack_trace(op.inner_outputs, new_out)
2325

2426
return new_out
@@ -62,7 +64,9 @@ def late_inline_OpFromGraph(fgraph, node):
6264
6365
"""
6466
op = node.op
65-
new_out = clone_replace(op.inner_outputs, dict(zip(op.inner_inputs, node.inputs)))
67+
new_out = clone_replace(
68+
op.inner_outputs, dict(zip(op.inner_inputs, node.inputs, strict=True))
69+
)
6670
copy_stack_trace(op.inner_outputs, new_out)
6771

6872
return new_out

0 commit comments

Comments
 (0)