From 2668cae090d5fda1d2cf54842746fc0cae441ba8 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Tue, 26 Apr 2022 00:14:37 -0700 Subject: [PATCH] Add PickleBuffer to _typeshed.WriteableBuffer (#7683) Fixes #4362 --- stdlib/_typeshed/__init__.pyi | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/stdlib/_typeshed/__init__.pyi b/stdlib/_typeshed/__init__.pyi index a80ea0702..baaa5e3c0 100644 --- a/stdlib/_typeshed/__init__.pyi +++ b/stdlib/_typeshed/__init__.pyi @@ -5,6 +5,7 @@ import array import ctypes import mmap +import pickle import sys from collections.abc import Awaitable, Container, Iterable, Set as AbstractSet from os import PathLike @@ -194,8 +195,13 @@ class SupportsWrite(Protocol[_T_contra]): ReadOnlyBuffer: TypeAlias = bytes # stable # Anything that implements the read-write buffer interface. # The buffer interface is defined purely on the C level, so we cannot define a normal Protocol -# for it. Instead we have to list the most common stdlib buffer classes in a Union. -WriteableBuffer: TypeAlias = bytearray | memoryview | array.array[Any] | mmap.mmap | ctypes._CData # stable +# for it (until PEP 688 is implemented). Instead we have to list the most common stdlib buffer classes in a Union. +if sys.version_info >= (3, 8): + WriteableBuffer: TypeAlias = ( + bytearray | memoryview | array.array[Any] | mmap.mmap | ctypes._CData | pickle.PickleBuffer + ) # stable +else: + WriteableBuffer: TypeAlias = bytearray | memoryview | array.array[Any] | mmap.mmap | ctypes._CData # stable # Same as _WriteableBuffer, but also includes read-only buffer types (like bytes). ReadableBuffer: TypeAlias = ReadOnlyBuffer | WriteableBuffer # stable