feat: cache is_unspecified for zeroconf ip address objects (#1331) · python-zeroconf/python-zeroconf@a1c84dc

@@ -34,13 +34,14 @@

34343535

class ZeroconfIPv4Address(IPv4Address):

363637-

__slots__ = ("_str", "_is_link_local")

37+

__slots__ = ("_str", "_is_link_local", "_is_unspecified")

38383939

def __init__(self, *args: Any, **kwargs: Any) -> None:

4040

"""Initialize a new IPv4 address."""

4141

super().__init__(*args, **kwargs)

4242

self._str = super().__str__()

4343

self._is_link_local = super().is_link_local

44+

self._is_unspecified = super().is_unspecified

44454546

def __str__(self) -> str:

4647

"""Return the string representation of the IPv4 address."""

@@ -51,16 +52,22 @@ def is_link_local(self) -> bool:

5152

"""Return True if this is a link-local address."""

5253

return self._is_link_local

535455+

@property

56+

def is_unspecified(self) -> bool:

57+

"""Return True if this is an unspecified address."""

58+

return self._is_unspecified

59+54605561

class ZeroconfIPv6Address(IPv6Address):

566257-

__slots__ = ("_str", "_is_link_local")

63+

__slots__ = ("_str", "_is_link_local", "_is_unspecified")

58645965

def __init__(self, *args: Any, **kwargs: Any) -> None:

6066

"""Initialize a new IPv6 address."""

6167

super().__init__(*args, **kwargs)

6268

self._str = super().__str__()

6369

self._is_link_local = super().is_link_local

70+

self._is_unspecified = super().is_unspecified

64716572

def __str__(self) -> str:

6673

"""Return the string representation of the IPv6 address."""

@@ -71,6 +78,11 @@ def is_link_local(self) -> bool:

7178

"""Return True if this is a link-local address."""

7279

return self._is_link_local

738081+

@property

82+

def is_unspecified(self) -> bool:

83+

"""Return True if this is an unspecified address."""

84+

return self._is_unspecified

85+74867587

@lru_cache(maxsize=512)

7688

def _cached_ip_addresses(address: Union[str, bytes, int]) -> Optional[Union[IPv4Address, IPv6Address]]: