From 7ffb7e0832871e26447cc951ed99216e06c7885a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mika=C3=ABl=20Capelle?= Date: Sat, 12 Apr 2025 19:09:31 +0200 Subject: [PATCH] Fix typing of Pickler.persistent_id and Unpickler.persistent_load for Python < 3.13. (#13818) --- stdlib/@tests/stubtest_allowlists/py310.txt | 6 ++++++ stdlib/@tests/stubtest_allowlists/py311.txt | 6 ++++++ stdlib/@tests/stubtest_allowlists/py312.txt | 6 ++++++ stdlib/@tests/stubtest_allowlists/py39.txt | 6 ++++++ stdlib/_pickle.pyi | 15 ++++++--------- 5 files changed, 30 insertions(+), 9 deletions(-) diff --git a/stdlib/@tests/stubtest_allowlists/py310.txt b/stdlib/@tests/stubtest_allowlists/py310.txt index d2d31ee8e..73bc3da9e 100644 --- a/stdlib/@tests/stubtest_allowlists/py310.txt +++ b/stdlib/@tests/stubtest_allowlists/py310.txt @@ -295,3 +295,9 @@ typing_extensions\.Annotated # Undocumented implementation details # (Remove once 3.10.17 becomes available for all platforms) (email._header_value_parser.get_encoded_word)? (email._header_value_parser.make_quoted_pairs)? + +# These methods have no default implementation for Python < 3.13. +_pickle.Pickler.persistent_id +_pickle.Unpickler.persistent_load +pickle.Pickler.persistent_id +pickle.Unpickler.persistent_load diff --git a/stdlib/@tests/stubtest_allowlists/py311.txt b/stdlib/@tests/stubtest_allowlists/py311.txt index 92a754386..655e603c0 100644 --- a/stdlib/@tests/stubtest_allowlists/py311.txt +++ b/stdlib/@tests/stubtest_allowlists/py311.txt @@ -259,3 +259,9 @@ typing_extensions\.Annotated # Undocumented implementation details # (Remove once 3.11.12 becomes available for all platforms) (email._header_value_parser.get_encoded_word)? (email._header_value_parser.make_quoted_pairs)? + +# These methods have no default implementation for Python < 3.13. +_pickle.Pickler.persistent_id +_pickle.Unpickler.persistent_load +pickle.Pickler.persistent_id +pickle.Unpickler.persistent_load diff --git a/stdlib/@tests/stubtest_allowlists/py312.txt b/stdlib/@tests/stubtest_allowlists/py312.txt index aaea70097..3222fed0d 100644 --- a/stdlib/@tests/stubtest_allowlists/py312.txt +++ b/stdlib/@tests/stubtest_allowlists/py312.txt @@ -228,3 +228,9 @@ sunau.Au_write.initfp threading.Lock # Factory function at runtime, but that wouldn't let us use it in type hints types.SimpleNamespace.__init__ # class doesn't accept positional arguments but has default C signature typing_extensions\.Annotated # Undocumented implementation details + +# These methods have no default implementation for Python < 3.13. +_pickle.Pickler.persistent_id +_pickle.Unpickler.persistent_load +pickle.Pickler.persistent_id +pickle.Unpickler.persistent_load diff --git a/stdlib/@tests/stubtest_allowlists/py39.txt b/stdlib/@tests/stubtest_allowlists/py39.txt index 04e9978a1..a912b6f85 100644 --- a/stdlib/@tests/stubtest_allowlists/py39.txt +++ b/stdlib/@tests/stubtest_allowlists/py39.txt @@ -245,3 +245,9 @@ typing_extensions\.Annotated # Undocumented implementation details # Incompatible changes introduced in Python 3.9.22 # (Remove once 3.9.22 becomes available for all platforms) (email._header_value_parser.get_encoded_word)? + +# These methods have no default implementation for Python < 3.13. +_pickle.Pickler.persistent_id +_pickle.Unpickler.persistent_load +pickle.Pickler.persistent_id +pickle.Unpickler.persistent_load diff --git a/stdlib/_pickle.pyi b/stdlib/_pickle.pyi index 50bbb6bc1..8e8afb600 100644 --- a/stdlib/_pickle.pyi +++ b/stdlib/_pickle.pyi @@ -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: ...