Skip to content

Conversation

damusss
Copy link
Member

@damusss damusss commented Oct 8, 2025

I'm splitting #3455 . This PR contains the four docstrings that are closely related to surface format internals and that have been rewritten almost entirely, requiring more attention.

@damusss damusss requested a review from a team as a code owner October 8, 2025 08:19
@damusss damusss added docs Surface pygame.Surface labels Oct 8, 2025
Copy link
Contributor

coderabbitai bot commented Oct 8, 2025

📝 Walkthrough

Walkthrough

Rewrote and expanded the Surface stub docstrings in buildconfig/stubs/pygame/surface.pyi to clarify surface creation, pixel-format control, transparency types, locking/subsurface behavior, convert/convert_alpha semantics (including pygame.error when display uninitialized), and flags. No signature/API changes.

Changes

Cohort / File(s) Summary of Changes
Pygame Surface stub doc updates
buildconfig/stubs/pygame/surface.pyi
Rewrote and expanded Surface docstrings: clarified how size and display affect format selection; described pixel-format control paths (flags, another Surface, depth/masks); enumerated transparency types and interactions (per-pixel, premultiplied, global alpha, colorkey) with performance notes; clarified locking/pixel-access and subsurface behavior; updated convert/convert_alpha descriptions including pygame.error when display is uninitialized; restructured flag listings and minor wording/formatting edits. No changes to function/class signatures or public API.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested reviewers

  • aatle
  • Starbuck5

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Title Check ✅ Passed The pull request title succinctly summarizes the main change, which is rewriting the Surface docstrings for object creation, convert methods, and flag descriptions, and it clearly reflects the content of the changeset without introducing unrelated noise.
Description Check ✅ Passed The pull request description clearly explains that this PR splits from a prior one and focuses on rewriting four docstrings related to surface format internals, which directly corresponds to the changes in the diff.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 963fef1 and 713eaea.

📒 Files selected for processing (1)
  • buildconfig/stubs/pygame/surface.pyi (3 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
buildconfig/stubs/pygame/surface.pyi (1)
src_py/__init__.py (1)
  • Surface (227-228)
🔇 Additional comments (4)
buildconfig/stubs/pygame/surface.pyi (4)

49-89: Excellent documentation improvements.

The rewritten Surface class docstring significantly improves clarity:

  • Clear explanation of Surface creation behavior (lines 49-53)
  • Well-structured enumeration of format control methods (lines 55-66)
  • Comprehensive coverage of transparency types (lines 78-89)
  • Helpful guidance on pixel access and performance (lines 99-114)

The new structure makes the documentation much more accessible for users.

Also applies to: 94-115


289-315: Clear and comprehensive convert() documentation.

The rewritten docstring effectively explains the multiple ways to control pixel format conversion:

  • No-argument form (display format matching)
  • Surface-based format copying
  • Bit depth and flags specification
  • Bitmask-based control

The documentation of the pygame.error exception (lines 298-299, 327) when the display Surface is uninitialized is a valuable addition for users.

Consider verifying the pygame.error behavior by checking the actual implementation or testing, though this appears consistent with standard pygame behavior.


317-330: Improved convert_alpha() clarity.

The updated documentation better explains the optimization trade-off: the resulting surface format is tailored for fast alpha blitting rather than exactly matching the display format. This is an important distinction for users to understand.


797-813: Well-organized flag documentation.

The restructured flag listing improves usability:

  • Clear enumeration of current flags with descriptions (lines 798-804)
  • Explicit reference to display-specific flags (lines 806-807)
  • Separated obsolete flags section for historical reference (lines 809-812)

This organization makes it easier for users to understand which flags are relevant for their use cases.

damusss and others added 3 commits October 8, 2025 10:21
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (3)
buildconfig/stubs/pygame/surface.pyi (3)

55-55: Minor grammar improvement.

The phrase "is providing" could be more idiomatic as "is by providing" or "is to provide".

Apply this diff:

-One way to control the pixel format/characteristics is providing a bitmask of flags:
+One way to control the pixel format/characteristics is by providing a bitmask of flags:

111-111: Simplify awkward formatting.

The phrase "lock()'ed" uses awkward formatting. Consider using "locked" for better readability.

Apply this diff:

-    Any functions that directly access a Surface's pixel data will need that
-    Surface to be lock()'ed in some cases. Built in functions that manipulate
+    Any functions that directly access a Surface's pixel data will need that
+    Surface to be locked in some cases. Built-in functions that manipulate
     Surfaces will lock and unlock the Surface automatically. Only use manual

Note: Also corrected "Built in" to "Built-in" for consistency.


306-307: Improve informal phrasing.

The phrase "calculated wrong" is informal. Use "incorrectly calculated" or "miscalculated" for more professional documentation.

Apply this diff:

-           * Passing the bitmasks of the pixels and flags. Note that the bit depth
-             could be calculated wrong, therefore it is not advised to use this
-             path as it might be deprecated in the future.
+           * Passing the bitmasks of the pixels and flags. Note that the bit depth
+             could be incorrectly calculated, therefore it is not advised to use this
+             approach as it might be deprecated in the future.

Note: Also changed "this path" to "this approach" for clarity.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1d063a8 and ee4614c.

📒 Files selected for processing (1)
  • buildconfig/stubs/pygame/surface.pyi (4 hunks)
🔇 Additional comments (2)
buildconfig/stubs/pygame/surface.pyi (2)

320-327: LGTM!

The convert_alpha() docstring clearly explains that the result is optimized for alpha blitting rather than matching the display format exactly, and correctly uses "raised" for the exception. The documentation accurately describes the behavior and constraints.


797-813: LGTM!

The get_flags() docstring provides a comprehensive and well-organized list of flags, clearly distinguishing between active, private, and obsolete flags. The explicit examples of obsolete flags help developers understand which features are no longer relevant in pygame 2.

All types of transparency can be used together and correctly mix, except
pre-multiplied alpha does not consider colorkey nor global alpha.
Also, An alpha of 255 is opaque while an alpha of 0 is fully transparent.
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

Fix capitalization error.

The word "An" should be lowercase "an" following a comma.

Apply this diff:

-    Also, An alpha of 255 is opaque while an alpha of 0 is fully transparent.
+    Also, an alpha of 255 is opaque while an alpha of 0 is fully transparent.
📝 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
Also, An alpha of 255 is opaque while an alpha of 0 is fully transparent.
Also, an alpha of 255 is opaque while an alpha of 0 is fully transparent.
🤖 Prompt for AI Agents
In buildconfig/stubs/pygame/surface.pyi around line 92, fix the capitalization
after the comma: change "An alpha of 255 is opaque while an alpha of 0 is fully
transparent." to use a lowercase "an" following the comma so the sentence reads
"...an alpha of 255 is opaque while an alpha of 0 is fully transparent."; update
the line accordingly and run a quick lint/typo check.

Comment on lines +298 to +299
A :class:`pygame.error` exception is thrown if the display Surface
was not initialized.
Copy link
Contributor

@coderabbitai coderabbitai bot Oct 11, 2025

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Use Python exception terminology.

Python exceptions are "raised" rather than "thrown". This ensures consistency with standard Python documentation conventions.

Apply this diff:

-             A :class:`pygame.error` exception is thrown if the display Surface
-             was not initialized.
+             A :class:`pygame.error` exception is raised if the display Surface
+             was not initialized.
📝 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
A :class:`pygame.error` exception is thrown if the display Surface
was not initialized.
A :class:`pygame.error` exception is raised if the display Surface
was not initialized.
🤖 Prompt for AI Agents
In buildconfig/stubs/pygame/surface.pyi around lines 298 to 299, the docstring
uses the term "thrown" for exceptions; replace it with Python terminology
"raised" so the sentence reads that "A :class:`pygame.error` exception is raised
if the display Surface was not initialized." Update the line accordingly to
maintain consistency with Python docs.

Copy link
Member Author

Choose a reason for hiding this comment

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

You're AI can you not notice this improvements one at a time so I don't spam commits 🙏

Copy link
Contributor

Choose a reason for hiding this comment

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

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Search for other instances of "thrown" in the surface.pyi file
rg -n "thrown" buildconfig/stubs/pygame/surface.pyi

Length of output: 83


@damusss, I understand! I've checked the entire file and this is actually the only instance of "thrown" vs "raised", so there's nothing else to batch with it for now.

For future reviews, I'll note to look for patterns across the entire PR and batch similar improvements together to minimize commits. 👍


🧬 Code Graph Analysis Results

[No. of relevant snippets: 4]

buildconfig/stubs/pygame/mixer.pyi, lines 76-76
def copy(self) -> Self: ...

buildconfig/stubs/pygame/cursors.pyi, lines 83-83
def copy(self) -> Cursor: ...

buildconfig/stubs/pygame/mask.pyi, lines 21-21
def copy(self) -> Mask: ...

buildconfig/stubs/pygame/pixelarray.pyi, lines 19-19
def surface(self) -> Surface: ...


✏️ Learnings added
Learnt from: damusss
PR: pygame-community/pygame-ce#3604
File: buildconfig/stubs/pygame/surface.pyi:298-299
Timestamp: 2025-10-11T10:24:52.698Z
Learning: For the pygame-community/pygame-ce repository, batch similar documentation or terminology improvements together in a single comment rather than pointing them out individually. This helps avoid unnecessary commit spam.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Surface pygame.Surface

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant