From ceb4cb42bd94eaa10ad41301e7d2fe2655f438e9 Mon Sep 17 00:00:00 2001 From: Semyon Moroz Date: Wed, 14 May 2025 10:25:22 +0000 Subject: [PATCH] Update `marshal.dump(s)` for 3.14 (#14059) --- stdlib/@tests/stubtest_allowlists/py314.txt | 2 -- stdlib/marshal.pyi | 20 ++++++++++++++------ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/stdlib/@tests/stubtest_allowlists/py314.txt b/stdlib/@tests/stubtest_allowlists/py314.txt index a63235b2d..fd7a51734 100644 --- a/stdlib/@tests/stubtest_allowlists/py314.txt +++ b/stdlib/@tests/stubtest_allowlists/py314.txt @@ -74,8 +74,6 @@ importlib.machinery.AppleFrameworkLoader importlib.util.__all__ importlib.util.Loader logging.handlers.SysLogHandler.__init__ -marshal.dump -marshal.dumps multiprocessing.forkserver.main multiprocessing.managers.BaseListProxy.clear multiprocessing.managers.BaseListProxy.copy diff --git a/stdlib/marshal.pyi b/stdlib/marshal.pyi index 6ab202637..46c421e4c 100644 --- a/stdlib/marshal.pyi +++ b/stdlib/marshal.pyi @@ -2,10 +2,10 @@ import builtins import sys import types from _typeshed import ReadableBuffer, SupportsRead, SupportsWrite -from typing import Any +from typing import Any, Final from typing_extensions import TypeAlias -version: int +version: Final[int] _Marshallable: TypeAlias = ( # handled in w_object() in marshal.c @@ -28,14 +28,22 @@ _Marshallable: TypeAlias = ( | ReadableBuffer ) -if sys.version_info >= (3, 13): +if sys.version_info >= (3, 14): + def dump(value: _Marshallable, file: SupportsWrite[bytes], version: int = 5, /, *, allow_code: bool = True) -> None: ... + def dumps(value: _Marshallable, version: int = 5, /, *, allow_code: bool = True) -> bytes: ... + +elif sys.version_info >= (3, 13): def dump(value: _Marshallable, file: SupportsWrite[bytes], version: int = 4, /, *, allow_code: bool = True) -> None: ... - def load(file: SupportsRead[bytes], /, *, allow_code: bool = True) -> Any: ... def dumps(value: _Marshallable, version: int = 4, /, *, allow_code: bool = True) -> bytes: ... - def loads(bytes: ReadableBuffer, /, *, allow_code: bool = True) -> Any: ... else: def dump(value: _Marshallable, file: SupportsWrite[bytes], version: int = 4, /) -> None: ... - def load(file: SupportsRead[bytes], /) -> Any: ... def dumps(value: _Marshallable, version: int = 4, /) -> bytes: ... + +if sys.version_info >= (3, 13): + def load(file: SupportsRead[bytes], /, *, allow_code: bool = True) -> Any: ... + def loads(bytes: ReadableBuffer, /, *, allow_code: bool = True) -> Any: ... + +else: + def load(file: SupportsRead[bytes], /) -> Any: ... def loads(bytes: ReadableBuffer, /) -> Any: ...