From 9aaa6191732e7ac7f3b2a9aecc43df4090ab8e74 Mon Sep 17 00:00:00 2001 From: Vincent Lafeychine Date: Mon, 1 Apr 2024 00:20:41 +0200 Subject: [PATCH] chore(bird): Improve code readability --- roles/bird/filter_plugins/bird.py | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/roles/bird/filter_plugins/bird.py b/roles/bird/filter_plugins/bird.py index 5bfae8f..00f38bb 100644 --- a/roles/bird/filter_plugins/bird.py +++ b/roles/bird/filter_plugins/bird.py @@ -89,7 +89,7 @@ class IPv4orIPv6(BaseModel): ipv6: list[int] = Field(ge=0, min_items=2, max_items=2) -class IPFlag(str): +class IPFlag: @classmethod def __get_validators__(cls): yield cls.validate @@ -236,14 +236,8 @@ def str_of_condition(condition: Condition, ctx: bool) -> str: return f"{min_v6} <= net.len && net.len <= {max_v6}" case NetMatch(matches=matches): - if ctx.ipv4: - networks = [ - m for m in matches if isinstance(m[0], IPv4Network) - ] - else: - networks = [ - m for m in matches if isinstance(m[0], IPv6Network) - ] + networkType = IPv4Network if ctx.ipv4 else IPv6Network + networks = [m for m in matches if isinstance(m[0], networkType)] return f"net ~ [ {', '.join([f'{network}{flag}' for (network, flag) in networks])} ]"