Skip to content
Open
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
47 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
05c1363
Merge branch 'main' of https://github.com/pygame-community/pygame-ce …
oddbookworm Feb 10, 2026
1715683
Port Image to C code
MightyJosip Feb 10, 2026
90dead1
Port Image to C code
MightyJosip Feb 10, 2026
1c81c76
Port Image to C code
MightyJosip Feb 10, 2026
e3b423b
Port Image to C code
MightyJosip Feb 10, 2026
e34b86c
Update render_test.py
MightyJosip Feb 10, 2026
f06fff4
Update render_test.py
MightyJosip Feb 10, 2026
17b9802
Update render_test.py
MightyJosip Feb 10, 2026
47e24a1
Update render_test.py
MightyJosip Feb 10, 2026
b49cbb6
Port Image to C code
MightyJosip Feb 10, 2026
d645561
Update render.c
MightyJosip Feb 10, 2026
c9e21c4
Update render.c
MightyJosip Feb 10, 2026
d54fd2c
Merge remote-tracking branch 'upstream/main' into NewImage
MightyJosip Feb 17, 2026
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: ...
Comment on lines +148 to +152
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 | 🔴 Critical

Union and Optional are used but not imported — this will fail type checking

Lines 150–151 use Union and Optional, but they aren't imported at line 2. The rest of this file uses the modern X | Y and X | None syntax (e.g., lines 26–28). Switch to the same style for consistency and to avoid the missing import.

🐛 Proposed fix
     def __init__(
         self,
-        texture_or_image: Union['Texture', 'Image'],
-        srcrect: Optional[RectLike] = None,
+        texture_or_image: "Texture" | "Image",
+        srcrect: RectLike | None = None,
     ) -> None: ...

Apply the same pattern to all other Optional usages in this class (lines 178, 180, 182, 184, 192, 193).

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
def __init__(
self,
texture_or_image: Union['Texture', 'Image'],
srcrect: Optional[RectLike] = None,
) -> None: ...
def __init__(
self,
texture_or_image: "Texture" | "Image",
srcrect: RectLike | None = None,
) -> None: ...
🤖 Prompt for AI Agents
In `@buildconfig/stubs/pygame/_render.pyi` around lines 148 - 152, The __init__
signature in this stub uses unimported typing names Union and Optional; replace
them with the modern PEP 604 style (use Texture | Image and RectLike | None or
RectLike | None as appropriate) to avoid missing imports and match the rest of
the file — update the __init__ parameter types in the class (the constructor def
__init__(self, texture_or_image: ... , srcrect: ... ) -> None) and apply the
same change to every other Optional/Union usage in this class (the other
method/attribute annotations that currently use Optional/Union) so the file
consistently uses X | Y and X | None instead of typing.Optional/typing.Union.

@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 +154 to +160
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 +181 to +184
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 | 🟡 Minor

srcrect getter return type should be Rect, not Optional[RectLike]

The C implementation (image_get_srcrect) always returns a pgRectObject — it never returns None. The getter return type should be Rect to match reality and provide accurate type information to consumers.

Also, as noted in a prior review, the setter should accept None (to reset to full-texture bounds) or the Optional annotation should be removed if None is not supported.

🔧 Proposed fix (assuming C setter is updated to accept None)
     `@property`
-    def srcrect(self) -> Optional[RectLike]: ...
+    def srcrect(self) -> Rect: ...
     `@srcrect.setter`
-    def srcrect(self, value: Optional[RectLike]) -> None: ...
+    def srcrect(self, value: RectLike | None) -> None: ...
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
@property
def srcrect(self) -> Optional[RectLike]: ...
@srcrect.setter
def srcrect(self, value: Optional[RectLike]) -> None: ...
`@property`
def srcrect(self) -> Rect: ...
`@srcrect.setter`
def srcrect(self, value: RectLike | None) -> None: ...
🤖 Prompt for AI Agents
In `@buildconfig/stubs/pygame/_render.pyi` around lines 181 - 184, The srcrect
property annotation is incorrect: the getter always returns a pgRectObject
(Rect) per the C implementation (image_get_srcrect), so change the getter return
type from Optional[RectLike] to Rect; also update the setter signature to accept
Optional[RectLike] (allowing None to reset bounds) or remove Optional if the C
setter does not accept None—ensure the annotations for "srcrect" (getter and
`@srcrect.setter`) match the C behavior (image_get_srcrect and the image setter)
so consumers get accurate types.

@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: ...
Loading
Loading