From 4d79f7c19fe232c683fd84dba455113f520e957e Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Fri, 31 Jul 2026 19:27:30 +0200 Subject: [PATCH] style(lint): state zip's strictness in the subnet regex `ruff`'s B905 wants every `zip()` to say whether it tolerates operands of different length. Here it never sees one: both operands are the `packed` form of an address from the same network, so both are four bytes for IPv4 and sixteen for IPv6. `strict=True` states that, and turns a silently truncated - and therefore too permissive - regex into an error should the invariant ever break. The three other files carry `ruff format` reflows the same run produced. Co-Authored-By: Claude Opus 5 (1M context) --- plugins/lookup/subnet_address_regex.py | 4 +++- plugins/lookup/subnet_gateway.py | 4 +++- tests/unit/scripts/test_roundtrip_marker.py | 4 +++- utils/networks/address.py | 5 ++++- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/plugins/lookup/subnet_address_regex.py b/plugins/lookup/subnet_address_regex.py index 5552952b48..c35818ff0b 100644 --- a/plugins/lookup/subnet_address_regex.py +++ b/plugins/lookup/subnet_address_regex.py @@ -52,7 +52,9 @@ class LookupModule(LookupBase): "subnet_address_regex lookup: application_id is required in variables" ) - config_lookup = lookup_loader.get("config", loader=self._loader, templar=templar) + config_lookup = lookup_loader.get( + "config", loader=self._loader, templar=templar + ) subnet = config_lookup.run( [str(application_id), "networks.local.subnet"], variables=vars_ )[0] diff --git a/plugins/lookup/subnet_gateway.py b/plugins/lookup/subnet_gateway.py index a10180ba0b..f723dbff62 100644 --- a/plugins/lookup/subnet_gateway.py +++ b/plugins/lookup/subnet_gateway.py @@ -49,7 +49,9 @@ class LookupModule(LookupBase): "subnet_gateway lookup: application_id is required in variables" ) - config_lookup = lookup_loader.get("config", loader=self._loader, templar=templar) + config_lookup = lookup_loader.get( + "config", loader=self._loader, templar=templar + ) subnet = config_lookup.run( [str(application_id), "networks.local.subnet"], variables=vars_ )[0] diff --git a/tests/unit/scripts/test_roundtrip_marker.py b/tests/unit/scripts/test_roundtrip_marker.py index 53765fe8d9..9e1ae703c5 100644 --- a/tests/unit/scripts/test_roundtrip_marker.py +++ b/tests/unit/scripts/test_roundtrip_marker.py @@ -7,7 +7,9 @@ import unittest from utils.cache.files import PROJECT_ROOT, read_text -DRILL = PROJECT_ROOT / "scripts" / "tests" / "deploy" / "swarm" / "routine" / "00_one.sh" +DRILL = ( + PROJECT_ROOT / "scripts" / "tests" / "deploy" / "swarm" / "routine" / "00_one.sh" +) GATE = PROJECT_ROOT / "scripts" / "tests" / "deploy" / "roundtrip.sh" MARKER = "==> swarm drill complete: app=" diff --git a/utils/networks/address.py b/utils/networks/address.py index b39279e5ea..7183c723e2 100644 --- a/utils/networks/address.py +++ b/utils/networks/address.py @@ -9,6 +9,7 @@ from __future__ import annotations import ipaddress + def _octet_pattern(low: int, high: int) -> str: if low == high: return str(low) @@ -39,7 +40,9 @@ def subnet_address_regex(subnet: str) -> str: return r"\.".join( _octet_pattern(low, high) for low, high in zip( - network.network_address.packed, network.broadcast_address.packed + network.network_address.packed, + network.broadcast_address.packed, + strict=True, ) )