diff --git a/buildconfig/stubs/pygame/bufferproxy.pyi b/buildconfig/stubs/pygame/bufferproxy.pyi index 58624cabdb..3275ffac53 100644 --- a/buildconfig/stubs/pygame/bufferproxy.pyi +++ b/buildconfig/stubs/pygame/bufferproxy.pyi @@ -1,3 +1,4 @@ +import sys from typing import Any class BufferProxy: @@ -13,5 +14,12 @@ class BufferProxy: def __array_interface__(self) -> dict[str, Any]: ... @property def __array_struct__(self) -> Any: ... + if sys.version_info >= (3, 12): + def __buffer__(self, flags: int, /) -> memoryview[int]: ... + def __release_buffer__(self, view: memoryview[int], /) -> None: ... def __init__(self, parent: Any) -> None: ... # TODO: parent: TypedDict | Protocol - def write(self, buffer: bytes, offset: int = 0) -> None: ... + def write( + self, + buffer: str | bytes, # See https://docs.python.org/3/c-api/arg.html at s# + offset: int = 0, + ) -> None: ... diff --git a/buildconfig/stubs/pygame/color.pyi b/buildconfig/stubs/pygame/color.pyi index 127c3225f7..ab3560971c 100644 --- a/buildconfig/stubs/pygame/color.pyi +++ b/buildconfig/stubs/pygame/color.pyi @@ -1,3 +1,4 @@ +import sys from collections.abc import Collection, Iterator from typing import Any, ClassVar, SupportsIndex, Union, overload @@ -21,6 +22,8 @@ class Color(Collection[int]): __hash__: ClassVar[None] # type: ignore[assignment] @property def __array_struct__(self) -> Any: ... + if sys.version_info >= (3, 12): + def __buffer__(self, flags: int, /) -> memoryview[int]: ... @overload def __init__(self, r: int, g: int, b: int, a: int = 255) -> None: ... @overload diff --git a/buildconfig/stubs/pygame/image.pyi b/buildconfig/stubs/pygame/image.pyi index 599ae07cb9..db44a8c4ea 100644 --- a/buildconfig/stubs/pygame/image.pyi +++ b/buildconfig/stubs/pygame/image.pyi @@ -3,9 +3,11 @@ from typing import Literal, Optional, Union from pygame.bufferproxy import BufferProxy from pygame.surface import Surface from pygame.typing import FileLike, IntPoint, Point -from typing_extensions import deprecated # added in 3.13 +from typing_extensions import ( + Buffer, # collections.abc 3.12 + deprecated, # added in 3.13 +) -_BufferLike = Union[BufferProxy, bytes, bytearray, memoryview] _from_buffer_format = Literal["P", "RGB", "BGR", "BGRA", "RGBX", "RGBA", "ARGB"] _to_bytes_format = Literal[ "P", "RGB", "RGBX", "RGBA", "ARGB", "BGRA", "ABGR", "RGBA_PREMULT", "ARGB_PREMULT" @@ -47,7 +49,7 @@ def frombytes( pitch: int = -1, ) -> Surface: ... def frombuffer( - buffer: _BufferLike, + buffer: Buffer, size: IntPoint, format: _from_buffer_format, pitch: int = -1, diff --git a/buildconfig/stubs/pygame/mask.pyi b/buildconfig/stubs/pygame/mask.pyi index 3dd1b109f2..722b9c67cc 100644 --- a/buildconfig/stubs/pygame/mask.pyi +++ b/buildconfig/stubs/pygame/mask.pyi @@ -1,3 +1,4 @@ +import sys from typing import Any, Optional, Union from pygame.rect import Rect @@ -53,6 +54,9 @@ class Mask: unsetcolor: Optional[ColorLike] = (0, 0, 0, 255), dest: Union[RectLike, Point] = (0, 0), ) -> Surface: ... + if sys.version_info >= (3, 12): + def __buffer__(self, flags: int, /) -> memoryview[int]: ... + def __release_buffer__(self, view: memoryview[int], /) -> None: ... @deprecated("Use `Mask` instead (MaskType is an old alias)") class MaskType(Mask): ... diff --git a/buildconfig/stubs/pygame/mixer.pyi b/buildconfig/stubs/pygame/mixer.pyi index 445b3c77cf..555375c1fd 100644 --- a/buildconfig/stubs/pygame/mixer.pyi +++ b/buildconfig/stubs/pygame/mixer.pyi @@ -1,9 +1,12 @@ +import sys from typing import Any, Optional, Union, overload -import numpy from pygame.event import Event from pygame.typing import FileLike -from typing_extensions import deprecated # added in 3.13 +from typing_extensions import ( + Buffer, # collections.abc 3.12 + deprecated, # added in 3.13 +) from . import mixer_music @@ -46,13 +49,7 @@ class Sound: @overload def __init__(self, file: FileLike) -> None: ... @overload - def __init__( - self, buffer: Any - ) -> None: ... # Buffer protocol is still not implemented in typing - @overload - def __init__( - self, array: numpy.ndarray - ) -> None: ... # Buffer protocol is still not implemented in typing + def __init__(self, buffer: Buffer) -> None: ... def play( self, loops: int = 0, @@ -65,6 +62,9 @@ class Sound: def __array_interface__(self) -> dict[str, Any]: ... @property def __array_struct__(self) -> Any: ... + if sys.version_info >= (3, 12): + def __buffer__(self, flags: int, /) -> memoryview[int]: ... + def __release_buffer__(self, view: memoryview[int], /) -> None: ... def stop(self) -> None: ... def fadeout(self, time: int, /) -> None: ... def set_volume(self, value: float, /) -> None: ... diff --git a/buildconfig/stubs/pygame/pixelarray.pyi b/buildconfig/stubs/pygame/pixelarray.pyi index 5df752c495..c51e2fe1a4 100644 --- a/buildconfig/stubs/pygame/pixelarray.pyi +++ b/buildconfig/stubs/pygame/pixelarray.pyi @@ -31,6 +31,8 @@ class PixelArray: def __array_interface__(self) -> dict[str, Any]: ... @property def __array_struct__(self) -> Any: ... + if sys.version_info >= (3, 12): + def __buffer__(self, flags: int, /) -> memoryview[int]: ... def __init__(self, surface: Surface) -> None: ... def __enter__(self) -> PixelArray: ... def __exit__(self, *args, **kwargs) -> None: ...