Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
5a8d38a
Add interface for _sdl2.video classes
MightyJosip Jan 28, 2025
1d2b186
Add interface for _sdl2.video classes
MightyJosip Jan 28, 2025
7898184
Add interface for _sdl2.video classes
MightyJosip Jan 28, 2025
3d2baa6
Add interface for _sdl2.video classes
MightyJosip Jan 28, 2025
a3cb1f9
Add interface for _sdl2.video classes
MightyJosip Jan 28, 2025
b15938e
Add interface for _sdl2.video classes
MightyJosip Jan 29, 2025
ef1c27d
Add interface for _sdl2.video classes
MightyJosip Jan 29, 2025
363a193
Add interface for _sdl2.video classes
MightyJosip Jan 29, 2025
363fa59
Add interface for _sdl2.video classes
MightyJosip Jan 29, 2025
afccd4b
Add interface for _sdl2.video classes
MightyJosip Feb 3, 2025
c6ba34d
Squashed commit of the following:
MightyJosip Jan 29, 2025
8bc95e5
Port Renderer to C code
MightyJosip Jan 30, 2025
9710ba9
Port Renderer to C code
MightyJosip Feb 3, 2025
844f787
Squashed commit of the following:
MightyJosip Jan 29, 2025
7354bfc
Port Texture to C code
MightyJosip Feb 7, 2025
98abc4a
Port Texture to C code
MightyJosip Feb 7, 2025
990e0e1
Port Image to C code
MightyJosip Feb 8, 2025
852440b
Port Image to C code
MightyJosip Feb 8, 2025
a288e3a
Port Image to C code
MightyJosip Feb 8, 2025
cb17e50
Port Image to C code
MightyJosip Feb 8, 2025
2f2d6fe
Port Image to C code
MightyJosip Feb 8, 2025
3d7afd9
Port Image to C code
MightyJosip Feb 8, 2025
2a77eec
Merge remote-tracking branch 'upstream/main' into NewImage
MightyJosip Aug 8, 2025
b15b920
Port Image to C code
MightyJosip Aug 8, 2025
fe9db88
Formatting
MyreMylar Aug 26, 2025
b5f507b
Merge branch 'main' into NewImage
MyreMylar Aug 26, 2025
32c4df7
merge Image code into render.c
MyreMylar Aug 26, 2025
4cd828c
resolve some dev-check errors
MyreMylar Aug 26, 2025
b475598
resolve some more dev-check errors
MyreMylar Aug 28, 2025
5b9bcd7
add some Image property stubs
MyreMylar Aug 28, 2025
9cb3a46
add some Image method stubs
MyreMylar Aug 28, 2025
d924463
Fix some memory allocation issues
MyreMylar Aug 31, 2025
59789b5
Correct type stubs
MyreMylar Aug 31, 2025
ef94d66
Add some basic tests (AI generated)
MyreMylar Aug 31, 2025
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
48 changes: 47 additions & 1 deletion buildconfig/stubs/pygame/_render.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,50 @@ class Texture:

@final
class Image:
pass
def __init__(
self,
texture_or_image: Union['Texture', 'Image'],
srcrect: Optional[RectLike] = None,
) -> None: ...
@property
def alpha(self) -> float: ...
@alpha.setter
def alpha(self, value: float) -> None: ...
@property
def angle(self) -> float: ...
@angle.setter
def angle(self, value: float) -> None: ...
Comment on lines +156 to +162
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

Alpha type differs from Texture.alpha

Image.alpha is typed as float here, while Texture.alpha is int. If fractional alpha isn’t intended as a public API difference, consider aligning Image.alpha to int for consistency, or document the divergence. Also, clamp in C to [0, 255] to avoid wrap-around on negative or >255 values.


🏁 Script executed:

#!/bin/bash
# Inspect recent lines around Image.alpha in _render.pyi
sed -n '140,200p' buildconfig/stubs/pygame/_render.pyi

# Locate the Texture class definition
rg -nP 'class Texture' -C3 buildconfig/stubs/pygame/_render.pyi

# Find all occurrences of .alpha in this file to compare types
rg -nP '\.alpha' -C2 buildconfig/stubs/pygame/_render.pyi

Length of output: 2169


🏁 Script executed:

#!/bin/bash
# List all .pyi stub files in pygame stubs directory
find buildconfig/stubs/pygame -type f -name '*.pyi'

# Search for Texture.alpha or any alpha definitions within Texture class
rg -nP 'class Texture' -C20 buildconfig/stubs/pygame/*.pyi | sed -n '1,100p'
rg -nP 'Texture.*alpha' -C2 buildconfig/stubs/pygame/*.pyi

# Search across all stub files for 'alpha(self)' to see type annotations
rg -nP 'def alpha' -C2 buildconfig/stubs/pygame/*.pyi

Length of output: 10391


Align or document alpha type mismatch: In buildconfig/stubs/pygame/_render.pyi, Texture.alpha (lines 90–92) is typed as int but Image.alpha (lines 156–158) uses float. Unless fractional alpha is a deliberate feature, change Image.alpha to int for consistency or document the intended float behavior. Also ensure the C implementation clamps values to [0, 255] to prevent wrap-around.

🤖 Prompt for AI Agents
In buildconfig/stubs/pygame/_render.pyi around lines 156–162 (and note
Texture.alpha at lines 90–92), Image.alpha is typed as float while Texture.alpha
is int; update Image.alpha to int for consistency (or if float is intended, add
a docstring explaining fractional alpha and behavior), adjust the setter
signature to accept int and return None, and ensure the C implementation clamps
input to the [0,255] range to avoid wrap-around (document clamping behavior in
the stub as well).

@property
def blend_mode(self) -> int: ...
@blend_mode.setter
def blend_mode(self, value: int) -> None: ...
@property
def color(self) -> Color: ...
@color.setter
def color(self, value: ColorLike) -> None: ...
@property
def flip_x(self) -> bool: ...
@flip_x.setter
def flip_x(self, value: bool) -> None: ...
@property
def flip_y(self) -> bool: ...
@flip_y.setter
def flip_y(self, value: bool) -> None: ...
@property
def origin(self) -> Optional[tuple[float, float]]: ...
@origin.setter
def origin(self, value: Optional[Point]) -> None: ...
@property
def srcrect(self) -> Optional[RectLike]: ...
@srcrect.setter
def srcrect(self, value: Optional[RectLike]) -> None: ...
Comment on lines +184 to +186
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

srcrect setter typed Optional in stubs, but C setter rejects None

The stub advertises srcrect: Optional[RectLike], while image_set_srcrect in C requires a Rect and errors on None. Either:

  • Accept None in C and reset to full texture bounds; or
  • Make the stub non-optional.

I’ve provided a C diff to accept None in my render.c comments.

@property
def texture(self) -> "Texture": ...
@texture.setter
def texture(self, value: "Texture") -> None: ...
def get_rect(self, **kwargs: Any) -> Rect: ...
def draw(
self,
srcrect: Optional[RectLike] = None,
dstrect: Optional[RectLike] = None,
) -> None: ...
Comment on lines +191 to +196
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Image.get_rect stub claims kwargs support, but C implementation is METH_NOARGS

In src_c/render.c, image_get_rect ignores kwargs. Either update the stub to def get_rect(self) -> Rect or (preferred) implement kwargs handling in C to match Texture.get_rect for consistency.

If you choose to implement kwargs handling, apply the C changes suggested in my render.c comments (image_get_rect + image_methods signature).

🤖 Prompt for AI Agents
In buildconfig/stubs/pygame/_render.pyi around lines 191 to 196, the
Image.get_rect stub declares kwargs support but the C implementation
(src_c/render.c image_get_rect) is METH_NOARGS and ignores kwargs; update the
implementation to accept and parse kwargs (match Texture.get_rect) or revert the
stub. Preferred: change image_get_rect to accept (PyObject *args, PyObject
*kwds), update its parsing to handle the same kwargs as Texture.get_rect, change
the method table entry to METH_VARARGS|METH_KEYWORDS, and keep the stub as def
get_rect(self, **kwargs: Any) -> Rect. If you choose the simpler route, change
the stub to def get_rect(self) -> Rect and leave C unchanged.

Loading
Loading