Fix typing of Pickler.persistent_id and Unpickler.persistent_load for Python < 3.13. (#13818)

This commit is contained in:
Mikaël Capelle
2025-04-12 19:09:31 +02:00
committed by GitHub
parent 76cd40e083
commit 7ffb7e0832
5 changed files with 30 additions and 9 deletions
+6 -9
View File
@@ -1,4 +1,3 @@
import sys
from _typeshed import ReadableBuffer, SupportsWrite
from collections.abc import Callable, Iterable, Iterator, Mapping
from pickle import PickleBuffer as PickleBuffer
@@ -75,10 +74,9 @@ class Pickler:
def memo(self, value: PicklerMemoProxy | dict[int, tuple[int, Any]]) -> None: ...
def dump(self, obj: Any, /) -> None: ...
def clear_memo(self) -> None: ...
if sys.version_info >= (3, 13):
def persistent_id(self, obj: Any, /) -> Any: ...
else:
persistent_id: Callable[[Any], Any]
# this method has no default implementation for Python < 3.13
def persistent_id(self, obj: Any, /) -> Any: ...
@type_check_only
class UnpicklerMemoProxy:
@@ -101,7 +99,6 @@ class Unpickler:
def memo(self, value: UnpicklerMemoProxy | dict[int, tuple[int, Any]]) -> None: ...
def load(self) -> Any: ...
def find_class(self, module_name: str, global_name: str, /) -> Any: ...
if sys.version_info >= (3, 13):
def persistent_load(self, pid: Any, /) -> Any: ...
else:
persistent_load: Callable[[Any], Any]
# this method has no default implementation for Python < 3.13
def persistent_load(self, pid: Any, /) -> Any: ...