From 6e5055ec92e679c75c36feb8d263ba91293f6b77 Mon Sep 17 00:00:00 2001 From: astitva Date: Wed, 1 Jul 2026 19:33:19 +0530 Subject: [PATCH 1/3] gh-152753: Fix memory leak in ipaddress properties by switching to cached_property --- Lib/ipaddress.py | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/Lib/ipaddress.py b/Lib/ipaddress.py index f1062a8cd052a5..238e2f6aa2c5ba 100644 --- a/Lib/ipaddress.py +++ b/Lib/ipaddress.py @@ -1264,7 +1264,7 @@ class IPv4Address(_BaseV4, _BaseAddress): """Represent and manipulate single IPv4 Addresses.""" - __slots__ = ('_ip', '__weakref__') + __slots__ = ('_ip', '__weakref__', '__dict__') def __init__(self, address): @@ -1317,8 +1317,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_ @@ -1339,8 +1338,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_ @@ -1548,8 +1546,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. @@ -1912,7 +1909,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. @@ -2085,8 +2082,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_ @@ -2424,4 +2420,4 @@ def __getattr__(name): _deprecated("__version__", remove=(3, 20)) return "1.0" # Do not change - raise AttributeError(f"module {__name__!r} has no attribute {name!r}") + raise AttributeError(f"module {__name__!r} has no attribute {name!r}") \ No newline at end of file From a1fd3d872d1833265e263c43a1cd21f4d3c2fd3f Mon Sep 17 00:00:00 2001 From: astitva Date: Wed, 1 Jul 2026 20:11:15 +0530 Subject: [PATCH 2/3] Fix trailing newline at end of file --- Lib/ipaddress.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/ipaddress.py b/Lib/ipaddress.py index 238e2f6aa2c5ba..6aa444009b8daa 100644 --- a/Lib/ipaddress.py +++ b/Lib/ipaddress.py @@ -2420,4 +2420,4 @@ def __getattr__(name): _deprecated("__version__", remove=(3, 20)) return "1.0" # Do not change - raise AttributeError(f"module {__name__!r} has no attribute {name!r}") \ No newline at end of file + raise AttributeError(f"module {__name__!r} has no attribute {name!r}") From 4548c14973ad4221d05e4493f171a4635c00b44e Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Wed, 1 Jul 2026 14:52:56 +0000 Subject: [PATCH 3/3] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../next/Library/2026-07-01-14-52-54.gh-issue-152753.IFTAg1.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2026-07-01-14-52-54.gh-issue-152753.IFTAg1.rst diff --git a/Misc/NEWS.d/next/Library/2026-07-01-14-52-54.gh-issue-152753.IFTAg1.rst b/Misc/NEWS.d/next/Library/2026-07-01-14-52-54.gh-issue-152753.IFTAg1.rst new file mode 100644 index 00000000000000..a732afd98a7810 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2026-07-01-14-52-54.gh-issue-152753.IFTAg1.rst @@ -0,0 +1 @@ +blurb new "Fix memory leak in ipaddress properties by switching from functools.lru_cache to functools.cached_property."