Skip to content

Remove legacy safe pickle system - #3857

Merged
oddbookworm merged 1 commit into
pygame-community:mainfrom
Starbuck5:remove-legacy-safe-pickle
Jul 31, 2026
Merged

oddbookworm merged 1 commit into
pygame-community:mainfrom
Starbuck5:remove-legacy-safe-pickle

Conversation

@Starbuck5

Copy link
Copy Markdown
Member

It is something to difficult figure out when this became irrelevant, but modern pickle-able classes do not need to have a __safe_for_unpickling__ property / method. PEP 303 from Python 2.3 talks about it in past tense (https://peps.python.org/pep-0307/#security-issues), but it is documented as needed until Python 2.7 (https://docs.python.org/release/2.7.18/library/pickle.html#pickling-and-unpickling-extension-types). By 3.1 at the latest, it was removed (https://docs.python.org/3.1/library/pickle.html#pickle.object.__reduce__)

It is something to difficult figure out when this became irrelevant, but modern pickle-able classes do not need to have a __safe_for_unpickling__ property / method. PEP 303 from Python 2.3 talks about it in past tense (https://peps.python.org/pep-0307/#security-issues), but it is documented as needed until Python 2.7 (https://docs.python.org/release/2.7.18/library/pickle.html#pickling-and-unpickling-extension-types). By 3.1 at the latest, it was removed (https://docs.python.org/3.1/library/pickle.html#pickle.object.__reduce__)
@Starbuck5 Starbuck5 added the Code quality/robustness Code quality and resilience to changes label Jul 25, 2026
@Starbuck5
Starbuck5 requested a review from a team as a code owner July 25, 2026 20:59
@coderabbitai

coderabbitai Bot commented Jul 25, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 37a66c46-b885-4b0a-a979-3629b93085c7

📥 Commits

Reviewing files that changed from the base of the PR and between 9e74166 and ed03c35.

📒 Files selected for processing (4)
  • buildconfig/stubs/pygame/math.pyi
  • buildconfig/stubs/pygame/rect.pyi
  • src_c/math.c
  • src_c/rect.c
💤 Files with no reviewable changes (3)
  • buildconfig/stubs/pygame/rect.pyi
  • buildconfig/stubs/pygame/math.pyi
  • src_c/rect.c

📝 Walkthrough

Walkthrough

Removes the __safe_for_unpickling__ helper implementations and exposed declarations from Vector2, Vector3, Rect, and FRect, along with their typing stubs.

Changes

Safe-unpickling marker removal

Layer / File(s) Summary
Vector marker removal
src_c/math.c, buildconfig/stubs/pygame/math.pyi
Removes the vector helper and __safe_for_unpickling__ entries from Vector2, Vector3, and their shared stub interface.
Rect marker removal
src_c/rect.c, buildconfig/stubs/pygame/rect.pyi
Removes the rect helper and __safe_for_unpickling__ getset entries from Rect, FRect, and their shared stub interface.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Suggested reviewers: damusss

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes removing the legacy safe_for_unpickling mechanism.
Description check ✅ Passed The description is on-topic and explains why the pickle safety marker was removed.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@ankith26 ankith26 left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I checked cpython sources and yes, I found this line

NOTE: checks for safe_for_unpickling went away in Python 2.3.

And of course, no line of code actually dealing with this attribute. We should be good to go with this cleanup (which is long overdue, over 23 years late xD)

@oddbookworm

Copy link
Copy Markdown
Member

I checked cpython sources and yes, I found this line

PEP-307 covered this, no need for source digging lol

@oddbookworm oddbookworm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thought I approved this before.... oops. LGTM!

@oddbookworm
oddbookworm merged commit ad864ad into pygame-community:main Jul 31, 2026
34 checks passed
@Starbuck5 Starbuck5 added this to the 2.5.8 milestone Jul 31, 2026
@Starbuck5
Starbuck5 deleted the remove-legacy-safe-pickle branch July 31, 2026 05:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Code quality/robustness Code quality and resilience to changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants