Skip to content

Commit c507028

Browse files
authored
Fix average_color docs and stubs to match implementation (#3076)
* Fix average_color docs and stubs to match implementation * Use RGBATuple for average_color and don't use it when it's not an RGBA tuple.
1 parent 0aeef1c commit c507028

File tree

5 files changed

+13
-14
lines changed

5 files changed

+13
-14
lines changed

buildconfig/stubs/pygame/display.pyi

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ from pygame.typing import (
1111
Coordinate,
1212
IntCoordinate,
1313
RectLike,
14-
RGBATuple,
1514
SequenceLike,
1615
)
1716

@@ -21,9 +20,9 @@ class _VidInfo:
2120
video_mem: int
2221
bitsize: int
2322
bytesize: int
24-
masks: RGBATuple
25-
shifts: RGBATuple
26-
losses: RGBATuple
23+
masks: Tuple[int, int, int, int]
24+
shifts: Tuple[int, int, int, int]
25+
losses: Tuple[int, int, int, int]
2726
blit_hw: int
2827
blit_hw_CC: int
2928
blit_hw_A: int

buildconfig/stubs/pygame/surface.pyi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,13 +152,13 @@ class Surface:
152152
def get_bytesize(self) -> int: ...
153153
def get_flags(self) -> int: ...
154154
def get_pitch(self) -> int: ...
155-
def get_masks(self) -> RGBATuple: ...
155+
def get_masks(self) -> Tuple[int, int, int, int]: ...
156156
@deprecated("since 2.0.0. Immutable in SDL2")
157157
def set_masks(self, color: ColorLike, /) -> None: ...
158-
def get_shifts(self) -> RGBATuple: ...
158+
def get_shifts(self) -> Tuple[int, int, int, int]: ...
159159
@deprecated("since 2.0.0. Immutable in SDL2")
160160
def set_shifts(self, color: ColorLike, /) -> None: ...
161-
def get_losses(self) -> RGBATuple: ...
161+
def get_losses(self) -> Tuple[int, int, int, int]: ...
162162
def get_bounding_rect(self, min_alpha: int = 1) -> Rect: ...
163163
def get_view(self, kind: _ViewKind = "2", /) -> BufferProxy: ...
164164
def get_buffer(self) -> BufferProxy: ...

buildconfig/stubs/pygame/transform.pyi

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
from typing import Optional, Union, Literal
22

3-
from pygame.color import Color
43
from pygame.surface import Surface
54

6-
from pygame.typing import ColorLike, Coordinate, RectLike, SequenceLike
5+
from pygame.typing import ColorLike, Coordinate, RectLike, SequenceLike, RGBATuple
76

87
def flip(surface: Surface, flip_x: bool, flip_y: bool) -> Surface: ...
98
def scale(
@@ -42,7 +41,7 @@ def average_surfaces(
4241
) -> Surface: ...
4342
def average_color(
4443
surface: Surface, rect: Optional[RectLike] = None, consider_alpha: bool = False
45-
) -> Color: ...
44+
) -> RGBATuple: ...
4645
def threshold(
4746
dest_surface: Optional[Surface],
4847
surface: Surface,

docs/reST/ref/transform.rst

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -306,11 +306,12 @@ Instead, always begin with the original image and scale to the desired size.)
306306
.. function:: average_color
307307

308308
| :sl:`finds the average color of a surface`
309-
| :sg:`average_color(surface, rect=None, consider_alpha=False) -> Color`
309+
| :sg:`average_color(surface, rect=None, consider_alpha=False) -> tuple`
310310
311311
Finds the average color of a Surface or a region of a surface specified by a
312-
Rect, and returns it as a Color. If consider_alpha is set to True, then alpha is
313-
taken into account (removing the black artifacts).
312+
Rect, and returns it as a tuple of integers red, green, blue, and alpha.
313+
If consider_alpha is set to True, then alpha is taken into account
314+
(removing the black artifacts).
314315

315316
.. versionaddedold:: 2.1.2 ``consider_alpha`` argument
316317

src_c/doc/transform_doc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#define DOC_TRANSFORM_BOXBLUR "box_blur(surface, radius, repeat_edge_pixels=True, dest_surface=None) -> Surface\nblur a surface using box blur"
1616
#define DOC_TRANSFORM_GAUSSIANBLUR "gaussian_blur(surface, radius, repeat_edge_pixels=True, dest_surface=None) -> Surface\nblur a surface using gaussian blur"
1717
#define DOC_TRANSFORM_AVERAGESURFACES "average_surfaces(surfaces, dest_surface=None, palette_colors=1) -> Surface\nfind the average surface from many surfaces."
18-
#define DOC_TRANSFORM_AVERAGECOLOR "average_color(surface, rect=None, consider_alpha=False) -> Color\nfinds the average color of a surface"
18+
#define DOC_TRANSFORM_AVERAGECOLOR "average_color(surface, rect=None, consider_alpha=False) -> tuple\nfinds the average color of a surface"
1919
#define DOC_TRANSFORM_INVERT "invert(surface, dest_surface=None) -> Surface\ninverts the RGB elements of a surface"
2020
#define DOC_TRANSFORM_GRAYSCALE "grayscale(surface, dest_surface=None) -> Surface\ngrayscale a surface"
2121
#define DOC_TRANSFORM_THRESHOLD "threshold(dest_surface, surface, search_color, threshold=(0,0,0,0), set_color=(0,0,0,0), set_behavior=1, search_surf=None, inverse_set=False) -> num_threshold_pixels\nfinds which, and how many pixels in a surface are within a threshold of a 'search_color' or a 'search_surf'."

0 commit comments

Comments
 (0)