Skip to content

Commit

Permalink
chore: Pass strict parameter to zip function call, as recommended per…
Browse files Browse the repository at this point in the history
… the B905 linting rule (#245)
  • Loading branch information
migueltorrescosta authored Jun 17, 2024
1 parent 89edc2d commit e0b40fb
Show file tree
Hide file tree
Showing 10 changed files with 16 additions and 10 deletions.
4 changes: 3 additions & 1 deletion guppylang/cfg/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,9 @@ def visit_Compare(
end_lineno=right.end_lineno,
end_col_offset=right.end_col_offset,
)
for left, op, right in zip(comparators[:-1], node.ops, comparators[1:])
for left, op, right in zip(
comparators[:-1], node.ops, comparators[1:], strict=True
)
]
conj = ast.BoolOp(op=ast.And(), values=values)
set_location_from(conj, node)
Expand Down
2 changes: 1 addition & 1 deletion guppylang/checker/expr_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ def type_check_args(
check_num_args(len(func_ty.inputs), len(inputs), node)

new_args: list[ast.expr] = []
for inp, ty in zip(inputs, func_ty.inputs):
for inp, ty in zip(inputs, func_ty.inputs, strict=True):
a, s = ExprChecker(ctx).check(inp, ty.substitute(subst), "argument")
new_args.append(a)
subst |= s
Expand Down
6 changes: 4 additions & 2 deletions guppylang/checker/func_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def check_global_func_def(
cfg = CFGBuilder().build(func_def.body, returns_none, globals)
inputs = [
Variable(x, ty, loc, None)
for x, ty, loc in zip(ty.input_names, ty.inputs, args)
for x, ty, loc in zip(ty.input_names, ty.inputs, args, strict=True)
]
return check_cfg(cfg, inputs, ty.output, globals)

Expand Down Expand Up @@ -88,7 +88,9 @@ def check_nested_func_def(
# Construct inputs for checking the body CFG
inputs = list(captured.values()) + [
Variable(x, ty, func_def.args.args[i], None)
for i, (x, ty) in enumerate(zip(func_ty.input_names, func_ty.inputs))
for i, (x, ty) in enumerate(
zip(func_ty.input_names, func_ty.inputs, strict=True)
)
]
def_id = DefId.fresh()
globals = ctx.globals
Expand Down
2 changes: 1 addition & 1 deletion guppylang/checker/stmt_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def _check_assign(self, lhs: ast.expr, ty: Type, node: ast.stmt) -> None:
f"(expected {n}, got {m})",
node,
)
for pat, el_ty in zip(elts, tys):
for pat, el_ty in zip(elts, tys, strict=True):
self._check_assign(pat, el_ty, node)

# TODO: Python also supports assignments like `[a, b] = [1, 2]` or
Expand Down
2 changes: 1 addition & 1 deletion guppylang/compiler/expr_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ def python_value_to_hugr(v: Any, exp_ty: Type) -> ops.Value | None:
assert isinstance(exp_ty, TupleType)
vs = [
python_value_to_hugr(elt, ty)
for elt, ty in zip(elts, exp_ty.element_types)
for elt, ty in zip(elts, exp_ty.element_types, strict=True)
]
if doesnt_contain_none(vs):
return ops.Value(ops.TupleValue(vs=vs))
Expand Down
4 changes: 3 additions & 1 deletion guppylang/error.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@ def format_source_location(
]
longest = max(len(ln) for ln in line_numbers)
prefixes = [ln + " " * (longest - len(ln) + indent) for ln in line_numbers]
res = "".join(prefix + line + "\n" for prefix, line in zip(prefixes, s[:-1]))
res = "".join(
prefix + line + "\n" for prefix, line in zip(prefixes, s[:-1], strict=False)
)
res += (longest + indent) * " " + s[-1]
return res

Expand Down
2 changes: 1 addition & 1 deletion guppylang/hugr_builder/hugr.py
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ def add_tag(
parent: Node | None = None,
) -> VNode:
"""Adds a `Tag` node to the graph."""
assert all(inp.ty == ty for inp, ty in zip(inputs, variants[tag]))
assert all(inp.ty == ty for inp, ty in zip(inputs, variants[tag], strict=True))
hugr_variants = rows_to_hugr(variants)
out_ty = SumType([row_to_type(row) for row in variants])
return self.add_node(
Expand Down
2 changes: 1 addition & 1 deletion guppylang/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ def get_py_scope(f: PyFunc) -> PyScope:

nonlocals: PyScope = {}
if f.__closure__ is not None:
for var, cell in zip(code.co_freevars, f.__closure__):
for var, cell in zip(code.co_freevars, f.__closure__, strict=True):
try:
value = cell.cell_contents
except ValueError:
Expand Down
1 change: 0 additions & 1 deletion ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ ignore = [
"EM102", # Exception must not use a string (an f-string) literal, assign to variable first
"S101", # Use of `assert` detected
"TRY003", # Avoid specifying long messages outside the exception class
"B905", # `zip()` without an explicit `strict=` parameter
]

[lint.per-file-ignores]
Expand Down
1 change: 1 addition & 0 deletions tests/integration/test_extern.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def main() -> int:
assert isinstance(c.v.root, ops.ExtensionValue)
assert c.v.root.value.v["symbol"] == "foo"


def test_extern_tuple(validate):
module = GuppyModule("module")

Expand Down

0 comments on commit e0b40fb

Please sign in to comment.