From 22676aec91bd92d4c5ced8a3844acabba1ed5ead Mon Sep 17 00:00:00 2001 From: Yun Zheng Hu Date: Wed, 22 Oct 2025 14:41:08 +0000 Subject: [PATCH] Fix ipnetwork __contains__ on Python 3.14 --- flow/record/fieldtypes/net/ip.py | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/flow/record/fieldtypes/net/ip.py b/flow/record/fieldtypes/net/ip.py index fdf6df88..94778259 100644 --- a/flow/record/fieldtypes/net/ip.py +++ b/flow/record/fieldtypes/net/ip.py @@ -73,20 +73,9 @@ def __eq__(self, b: _ConversionTypes | _IPNetwork) -> bool: def __hash__(self) -> int: return hash(self.val) - @staticmethod - def _is_subnet_of(a: _IPNetwork, b: _IPNetwork) -> bool: - try: - # Always false if one is v4 and the other is v6. - if a._version != b._version: - raise TypeError(f"{a} and {b} are not of the same version") - except AttributeError: - raise TypeError(f"Unable to test subnet containment between {a} and {b}") - else: - return b.network_address <= a.network_address and b.broadcast_address >= a.broadcast_address - def __contains__(self, b: object) -> bool: try: - return self._is_subnet_of(ip_network(b), self.val) + return ip_network(b).subnet_of(self.val) except (ValueError, TypeError): return False