feat: cache is_unspecified for zeroconf ip address objects by bdraco · Pull Request #1331 · python-zeroconf/python-zeroconf

Expand Up @@ -34,13 +34,14 @@
class ZeroconfIPv4Address(IPv4Address):
__slots__ = ("_str", "_is_link_local") __slots__ = ("_str", "_is_link_local", "_is_unspecified")
def __init__(self, *args: Any, **kwargs: Any) -> None: """Initialize a new IPv4 address.""" super().__init__(*args, **kwargs) self._str = super().__str__() self._is_link_local = super().is_link_local self._is_unspecified = super().is_unspecified
def __str__(self) -> str: """Return the string representation of the IPv4 address.""" Expand All @@ -51,16 +52,22 @@ def is_link_local(self) -> bool: """Return True if this is a link-local address.""" return self._is_link_local
@property def is_unspecified(self) -> bool: """Return True if this is an unspecified address.""" return self._is_unspecified

class ZeroconfIPv6Address(IPv6Address):
__slots__ = ("_str", "_is_link_local") __slots__ = ("_str", "_is_link_local", "_is_unspecified")
def __init__(self, *args: Any, **kwargs: Any) -> None: """Initialize a new IPv6 address.""" super().__init__(*args, **kwargs) self._str = super().__str__() self._is_link_local = super().is_link_local self._is_unspecified = super().is_unspecified
def __str__(self) -> str: """Return the string representation of the IPv6 address.""" Expand All @@ -71,6 +78,11 @@ def is_link_local(self) -> bool: """Return True if this is a link-local address.""" return self._is_link_local
@property def is_unspecified(self) -> bool: """Return True if this is an unspecified address.""" return self._is_unspecified

@lru_cache(maxsize=512) def _cached_ip_addresses(address: Union[str, bytes, int]) -> Optional[Union[IPv4Address, IPv6Address]]: Expand Down