-
-
Notifications
You must be signed in to change notification settings - Fork 230
Port Image to C code #3331
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
base: main
Are you sure you want to change the base?
Port Image to C code #3331
Changes from 35 commits
5a8d38a
1d2b186
7898184
3d2baa6
a3cb1f9
b15938e
ef1c27d
363a193
363fa59
afccd4b
c6ba34d
8bc95e5
9710ba9
844f787
7354bfc
98abc4a
990e0e1
852440b
a288e3a
cb17e50
2f2d6fe
3d7afd9
2a77eec
b15b920
fe9db88
b5f507b
32c4df7
4cd828c
b475598
5b9bcd7
9cb3a46
d924463
59789b5
ef94d66
05c1363
1715683
90dead1
1c81c76
e3b423b
e34b86c
f06fff4
17b9802
47e24a1
b49cbb6
d645561
c9e21c4
d54fd2c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -145,4 +145,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
+154
to
+160
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chainAlpha 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.pyiLength 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/*.pyiLength of output: 10391 Align or document alpha type mismatch: In 🤖 Prompt for AI Agents |
||||||||||||||||||
| @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: ... | ||||||||||||||||||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
Comment on lines
+181
to
+184
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The C implementation ( Also, as noted in a prior review, the setter should accept 🔧 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
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||
| @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: ... | ||||||||||||||||||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
UnionandOptionalare used but not imported — this will fail type checkingLines 150–151 use
UnionandOptional, but they aren't imported at line 2. The rest of this file uses the modernX | YandX | Nonesyntax (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
Optionalusages in this class (lines 178, 180, 182, 184, 192, 193).📝 Committable suggestion
🤖 Prompt for AI Agents