Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pygame.typing module #3002

Merged
merged 20 commits into from
Aug 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions buildconfig/stubs/gen_stubs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"""

import pathlib
import shutil
from typing import Any

import pygame.constants
Expand Down Expand Up @@ -51,6 +52,7 @@
"system",
"geometry",
"window",
"typing",
]

# pygame classes that are autoimported into main namespace are kept in this dict
Expand Down Expand Up @@ -151,3 +153,6 @@ def get_all(mod: Any):
for element in get_all(pygame.locals):
constant_type = getattr(pygame.locals, element).__class__.__name__
f.write(f"{element}: {constant_type}\n")

# copy typing.py to typing.pyi for type checkers
shutil.copyfile("src_py/typing.py", "buildconfig/stubs/pygame/typing.pyi")
damusss marked this conversation as resolved.
Show resolved Hide resolved
4 changes: 0 additions & 4 deletions buildconfig/stubs/mypy_allow_list.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
# listed here are not checked by the mypy stubtest program
# This allowlist supports regex

# This is not a real typestub file, it is used only in the typestubs to export
# a few utility typestub definitions
pygame\._common

# cython files have this top level dunder
pygame\._sdl2\..*\.__test__

Expand Down
1 change: 1 addition & 0 deletions buildconfig/stubs/pygame/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ from pygame import (
system as system,
geometry as geometry,
window as window,
typing as typing,
)

from .rect import Rect as Rect, FRect as FRect
Expand Down
101 changes: 0 additions & 101 deletions buildconfig/stubs/pygame/_common.pyi

This file was deleted.

70 changes: 35 additions & 35 deletions buildconfig/stubs/pygame/_sdl2/video.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ from pygame.rect import Rect
from pygame.surface import Surface
from pygame.window import Window as Window

from .._common import ColorValue, RectValue, Coordinate
from pygame.typing import ColorLike, RectLike, CoordinateLike

WINDOWPOS_UNDEFINED: int
WINDOWPOS_CENTERED: int
Expand Down Expand Up @@ -60,56 +60,56 @@ class Texture:
@property
def color(self) -> Color: ...
@color.setter
def color(self, value: ColorValue) -> None: ...
def color(self, value: ColorLike) -> None: ...

def get_rect(self, **kwargs: Any) -> Rect: ...
def draw(
self,
srcrect: Optional[RectValue] = None,
dstrect: Optional[RectValue] = None,
srcrect: Optional[RectLike] = None,
dstrect: Optional[RectLike] = None,
angle: float = 0.0,
origin: Optional[Iterable[int]] = None,
flip_x: bool = False,
flip_y: bool = False,
) -> None: ...
def draw_triangle(
self,
p1_xy: Coordinate,
p2_xy: Coordinate,
p3_xy: Coordinate,
p1_uv: Coordinate = (0.0, 0.0),
p2_uv: Coordinate = (1.0, 1.0),
p3_uv: Coordinate = (0.0, 1.0),
p1_xy: CoordinateLike,
p2_xy: CoordinateLike,
p3_xy: CoordinateLike,
p1_uv: CoordinateLike = (0.0, 0.0),
p2_uv: CoordinateLike = (1.0, 1.0),
p3_uv: CoordinateLike = (0.0, 1.0),
p1_mod: Iterable[int] = (255, 255, 255, 255),
p2_mod: Iterable[int] = (255, 255, 255, 255),
p3_mod: Iterable[int] = (255, 255, 255, 255),
) -> None: ...
def draw_quad(
self,
p1_xy: Coordinate,
p2_xy: Coordinate,
p3_xy: Coordinate,
p4_xy: Coordinate,
p1_uv: Coordinate = (0.0, 0.0),
p2_uv: Coordinate = (1.0, 0.0),
p3_uv: Coordinate = (1.0, 1.0),
p4_uv: Coordinate = (0.0, 1.0),
p1_xy: CoordinateLike,
p2_xy: CoordinateLike,
p3_xy: CoordinateLike,
p4_xy: CoordinateLike,
p1_uv: CoordinateLike = (0.0, 0.0),
p2_uv: CoordinateLike = (1.0, 0.0),
p3_uv: CoordinateLike = (1.0, 1.0),
p4_uv: CoordinateLike = (0.0, 1.0),
p1_mod: Iterable[int] = (255, 255, 255, 255),
p2_mod: Iterable[int] = (255, 255, 255, 255),
p3_mod: Iterable[int] = (255, 255, 255, 255),
p4_mod: Iterable[int] = (255, 255, 255, 255),
) -> None: ...
def update(self, surface: Surface, area: Optional[RectValue] = None) -> None: ...
def update(self, surface: Surface, area: Optional[RectLike] = None) -> None: ...

class Image:
def __init__(
self,
texture_or_image: Union[Texture, Image],
srcrect: Optional[RectValue] = None,
srcrect: Optional[RectLike] = None,
) -> None: ...
def get_rect(self) -> Rect: ...
def draw(
self, srcrect: Optional[RectValue] = None, dstrect: Optional[RectValue] = None
self, srcrect: Optional[RectLike] = None, dstrect: Optional[RectLike] = None
) -> None: ...
angle: float
origin: Optional[Iterable[float]]
Expand All @@ -123,7 +123,7 @@ class Image:
@property
def color(self) -> Color: ...
@color.setter
def color(self, value: ColorValue) -> None: ...
def color(self, value: ColorLike) -> None: ...

class Renderer:
def __init__(
Expand All @@ -140,39 +140,39 @@ class Renderer:
@property
def draw_color(self) -> Color: ...
@draw_color.setter
def draw_color(self, value: ColorValue) -> None: ...
def draw_color(self, value: ColorLike) -> None: ...
def clear(self) -> None: ...
def present(self) -> None: ...
def get_viewport(self) -> Rect: ...
def set_viewport(self, area: Optional[RectValue]) -> None: ...
def set_viewport(self, area: Optional[RectLike]) -> None: ...
logical_size: Iterable[int]
scale: Iterable[float]
target: Optional[Texture]
def blit(
self,
source: Union[Texture, Image],
dest: Optional[RectValue] = None,
area: Optional[RectValue] = None,
dest: Optional[RectLike] = None,
area: Optional[RectLike] = None,
special_flags: int = 0,
) -> Rect: ...
def draw_line(self, p1: Coordinate, p2: Coordinate) -> None: ...
def draw_point(self, point: Coordinate) -> None: ...
def draw_rect(self, rect: RectValue) -> None: ...
def fill_rect(self, rect: RectValue) -> None: ...
def draw_line(self, p1: CoordinateLike, p2: CoordinateLike) -> None: ...
def draw_point(self, point: CoordinateLike) -> None: ...
def draw_rect(self, rect: RectLike) -> None: ...
def fill_rect(self, rect: RectLike) -> None: ...
def draw_triangle(
self, p1: Coordinate, p2: Coordinate, p3: Coordinate
self, p1: CoordinateLike, p2: CoordinateLike, p3: CoordinateLike
) -> None: ...
def fill_triangle(
self, p1: Coordinate, p2: Coordinate, p3: Coordinate
self, p1: CoordinateLike, p2: CoordinateLike, p3: CoordinateLike
) -> None: ...
def draw_quad(
self, p1: Coordinate, p2: Coordinate, p3: Coordinate, p4: Coordinate
self, p1: CoordinateLike, p2: CoordinateLike, p3: CoordinateLike, p4: CoordinateLike
) -> None: ...
def fill_quad(
self, p1: Coordinate, p2: Coordinate, p3: Coordinate, p4: Coordinate
self, p1: CoordinateLike, p2: CoordinateLike, p3: CoordinateLike, p4: CoordinateLike
) -> None: ...
def to_surface(
self, surface: Optional[Surface] = None, area: Optional[RectValue] = None
self, surface: Optional[Surface] = None, area: Optional[RectLike] = None
) -> Surface: ...
@staticmethod
def compose_custom_blend_mode(
Expand Down
4 changes: 2 additions & 2 deletions buildconfig/stubs/pygame/camera.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from abc import ABC, abstractmethod
from typing import List, Optional, Tuple, Union, Literal

from ._common import IntCoordinate
from pygame.typing import IntCoordinateLike

from pygame.surface import Surface

Expand Down Expand Up @@ -36,7 +36,7 @@ class Camera(AbstractCamera):
def __init__(
self,
device: Union[str, int] = 0,
size: IntCoordinate = (640, 480),
size: IntCoordinateLike = (640, 480),
format: str = "RGB",
) -> None: ...
def start(self) -> None: ...
Expand Down
8 changes: 4 additions & 4 deletions buildconfig/stubs/pygame/color.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import sys
from typing import Any, Dict, Iterator, SupportsIndex, Tuple, Union, overload
from typing_extensions import deprecated # added in 3.13

from ._common import ColorValue
from pygame.typing import ColorLike

if sys.version_info >= (3, 9):
from collections.abc import Collection
Expand All @@ -28,7 +28,7 @@ class Color(Collection[int]):
@overload
def __init__(self, r: int, g: int, b: int, a: int = 255) -> None: ...
@overload
def __init__(self, rgbvalue: ColorValue) -> None: ...
def __init__(self, rgbvalue: ColorLike) -> None: ...
@overload
def __getitem__(self, i: SupportsIndex) -> int: ...
@overload
Expand Down Expand Up @@ -82,10 +82,10 @@ class Color(Collection[int]):
def correct_gamma(self, gamma: float, /) -> Color: ...
@deprecated("since 2.1.3. Use unpacking instead")
def set_length(self, length: int, /) -> None: ...
def lerp(self, color: ColorValue, amount: float) -> Color: ...
def lerp(self, color: ColorLike, amount: float) -> Color: ...
def premul_alpha(self) -> Color: ...
def grayscale(self) -> Color: ...
@overload
def update(self, r: int, g: int, b: int, a: int = 255, /) -> None: ...
@overload
def update(self, rgbvalue: ColorValue, /) -> None: ...
def update(self, rgbvalue: ColorLike, /) -> None: ...
Loading
Loading