Skip to content

Preserve descriptors when saving patched methods - #968

Open
remote-controlled-man wants to merge 5 commits into
AnswerDotAI:mainfrom
remote-controlled-man:codex/prflow-90c26b9711c2
Open

remote-controlled-man wants to merge 5 commits into
AnswerDotAI:mainfrom
remote-controlled-man:codex/prflow-90c26b9711c2

Conversation

@remote-controlled-man

@remote-controlled-man remote-controlled-man commented Nov 15, 2026 •

Copy link
Copy Markdown

Fixes #967.

When patch or patch_to replaces a class method, its saved _orig_* method stays bound to the base class. An original static method accessed through an instance receives an unwanted self argument and raises TypeError.

Save class and static method descriptors when their binding matches the attribute Python resolved. Keep the resolved value for metaclass overrides and dynamic class attributes. Update the owning Notebook and generated module together.

Regression coverage exercises class and instance access, subclasses, built-in and patched class methods, inherited originals, static methods, renaming and repeated patches, plus ordinary methods, properties, dynamic attributes, and a same-name metaclass property.

Synced with main at f387a6a. The owning notebook remains ship/01_basics.ipynb, with its Fastship export in fastcore/basics.py.

Validation on macOS, Python 3.12.14, Fastship 0.1.23:

  • On unmodified main, the saved class method resolves to the original base class and the saved static method receives an extra argument through an instance. The four descriptor regression cells pass on this branch.
  • All 23 notebooks and the literate fastcore/diff.py module passed through the ship-test entry point after preloading standard-library XML. The stock invocation hits the same XML import-shadowing error on both trees.
  • ship-clean leaves both trees clean. ship-export reports identical unrelated documentation-index changes on both trees. The descriptor export is in sync, and git diff --check passed.

Other CI platforms and Python versions were not run locally.

AI assistance: OpenAI Codex assisted implementation, tests and independent review.

Copilot AI balanced review requested due to automatic review settings November 15, 2026 13:31

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Saved original class and static methods lose descriptor binding

2 participants