Improve CPython compatibility related with PyBoundMethod - #7476
Conversation
CPython's method_descr_get always returns the bound method unchanged. This preserves the original binding when __get__ is called on an already-bound method (e.g. a.meth.__get__(b, B) still returns a). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Reject non-callable functions and None instances, matching CPython's method_new which checks PyCallable_Check(func) and instance != Py_None. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Previously swallowed errors from get_attr with .ok(), silently returning None. Now propagates errors matching CPython's method_reduce. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
π¦ Library DependenciesThe following Lib/ modules were modified. Here are their dependencies: [ ] test: cpython/Lib/test/test_descr.py (TODO: 42) dependencies: dependent tests: (no tests depend on descr) Legend:
|
|
No actionable comments were generated in the recent review. π βΉοΈ Recent review infoβοΈ Run configurationConfiguration used: Path: .coderabbit.yml Review profile: CHILL Plan: Pro Run ID: β Files ignored due to path filters (1)
π Files selected for processing (1)
π WalkthroughWalkthroughThis PR enhances Changes
Estimated code review effortπ― 2 (Simple) | β±οΈ ~10 minutes Possibly related PRs
Suggested reviewers
Poem
π₯ Pre-merge checks | β 2 | β 1β Failed checks (1 warning)
β Passed checks (2 passed)
βοΈ Tip: You can configure your own custom pre-merge checks in the settings. β¨ Finishing Touchesπ§ͺ Generate unit tests (beta)
π Coding Plan
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. Comment |
* Add GetDescriptor for PyBoundMethod (return self) CPython's method_descr_get always returns the bound method unchanged. This preserves the original binding when __get__ is called on an already-bound method (e.g. a.meth.__get__(b, B) still returns a). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * Add constructor validation for PyBoundMethod Reject non-callable functions and None instances, matching CPython's method_new which checks PyCallable_Check(func) and instance != Py_None. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * Fix PyBoundMethod __reduce__ to propagate errors Previously swallowed errors from get_attr with .ok(), silently returning None. Now propagates errors matching CPython's method_reduce. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This pull request adjusts PyBoundMethod for compatibility with CPython.
Behavior changes
__get____name__when callingPyBoundMethod__reduce__CPython (3.14.3)
RustPython (before this pull request)
RustPython (after this pull request)
Summary by CodeRabbit
Noneas the object parameter now correctly raises aTypeError.