From 08cd64c9faaa14e752df27446af45ba0485c1e03 Mon Sep 17 00:00:00 2001 From: Karolina Surma Date: Tue, 10 Mar 2026 14:39:28 +0100 Subject: [PATCH 1/2] Fix pickling URLs with Python 3.15.0a6+ (Fixes #1632) In Python 3.15 urllib.parse.SplitResult gained a new __getstate__ method which fails when called on instances created via tuple.__new__: https://github.com/python/cpython/commit/c5cfcdf1 Returning self._val directly instead of creating a new SplitResult instance avoids the problematic code path, and is backwards compatible. --- yarl/_url.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/yarl/_url.py b/yarl/_url.py index 5a79fe1f8..07b633fe3 100644 --- a/yarl/_url.py +++ b/yarl/_url.py @@ -566,8 +566,8 @@ def __mod__(self, query: Query) -> "URL": def __bool__(self) -> bool: return bool(self._netloc or self._path or self._query or self._fragment) - def __getstate__(self) -> tuple[SplitResult]: - return (tuple.__new__(SplitResult, self._val),) + def __getstate__(self) -> tuple[SplitURLType]: + return (self._val,) def __setstate__( self, state: tuple[SplitURLType] | tuple[None, _InternalURLCache] From 6527b4f000fa88a568659e3f47f81dc6c57b6c49 Mon Sep 17 00:00:00 2001 From: Karolina Surma Date: Tue, 10 Mar 2026 14:58:28 +0100 Subject: [PATCH 2/2] Add news entry --- CHANGES/1642.bugfix.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 CHANGES/1642.bugfix.rst diff --git a/CHANGES/1642.bugfix.rst b/CHANGES/1642.bugfix.rst new file mode 100644 index 000000000..2eae40c7d --- /dev/null +++ b/CHANGES/1642.bugfix.rst @@ -0,0 +1 @@ +Fixed pickle compatibility with Python 3.15. -- by :user:`befeleme`.