Skip to content
16 changes: 6 additions & 10 deletions Lib/ipaddress.py
Original file line number Diff line number Diff line change
Expand Up @@ -1305,7 +1305,7 @@ class IPv4Address(_BaseV4, _BaseAddress):

"""Represent and manipulate single IPv4 Addresses."""

__slots__ = ('_ip', '__weakref__')
__slots__ = ('_ip', '__weakref__', '__dict__')

def __init__(self, address):

Expand Down Expand Up @@ -1358,8 +1358,7 @@ def is_reserved(self):
"""
return self in self._constants._reserved_network

@property
@functools.lru_cache()
@functools.cached_property
def is_private(self):
"""``True`` if the address is defined as not globally reachable by
iana-ipv4-special-registry_ (for IPv4) or iana-ipv6-special-registry_
Expand All @@ -1380,8 +1379,7 @@ def is_private(self):
and all(self not in net for net in self._constants._private_networks_exceptions)
)

@property
@functools.lru_cache()
@functools.cached_property
def is_global(self):
"""``True`` if the address is defined as globally reachable by
iana-ipv4-special-registry_ (for IPv4) or iana-ipv6-special-registry_
Expand Down Expand Up @@ -1589,8 +1587,7 @@ def __init__(self, address, strict=True):
elif self._prefixlen == (self.max_prefixlen):
self.hosts = lambda: iter((IPv4Address(addr),))

@property
@functools.lru_cache()
@functools.cached_property
def is_global(self):
"""Test if this address is allocated for public networks.

Expand Down Expand Up @@ -1953,7 +1950,7 @@ class IPv6Address(_BaseV6, _BaseAddress):

"""Represent and manipulate single IPv6 Addresses."""

__slots__ = ('_ip', '_scope_id', '__weakref__')
__slots__ = ('_ip', '_scope_id', '__weakref__', '__dict__')

def __init__(self, address):
"""Instantiate a new IPv6 address object.
Expand Down Expand Up @@ -2126,8 +2123,7 @@ def is_site_local(self):
"""
return self in self._constants._sitelocal_network

@property
@functools.lru_cache()
@functools.cached_property
def is_private(self):
"""``True`` if the address is defined as not globally reachable by
iana-ipv4-special-registry_ (for IPv4) or iana-ipv6-special-registry_
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix memory leak in ipaddress properties by switching from :func:`functools.lru_cache` to :func:`functools.cached_property`.
Loading