Skip to content

Commit 08cd64c

Browse files
committed
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__: python/cpython@c5cfcdf1 Returning self._val directly instead of creating a new SplitResult instance avoids the problematic code path, and is backwards compatible.
1 parent 148fc70 commit 08cd64c

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

yarl/_url.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -566,8 +566,8 @@ def __mod__(self, query: Query) -> "URL":
566566
def __bool__(self) -> bool:
567567
return bool(self._netloc or self._path or self._query or self._fragment)
568568

569-
def __getstate__(self) -> tuple[SplitResult]:
570-
return (tuple.__new__(SplitResult, self._val),)
569+
def __getstate__(self) -> tuple[SplitURLType]:
570+
return (self._val,)
571571

572572
def __setstate__(
573573
self, state: tuple[SplitURLType] | tuple[None, _InternalURLCache]

0 commit comments

Comments
 (0)