Repository navigation
Bind receivers for ordinary functions stored on classes - #904
Open
yangfan-yf-yf wants to merge 1 commit into
Open
yangfan-yf-yf wants to merge 1 commit into
yangfan-yf-yf wants to merge 1 commit into
Conversation
Retain the receiver in direct and saved class-slot access values without changing the original function's lexical parent or source bindings. Preserve inherited and imported functions and direct instance overrides. Record canonical calls during analysis and persist bound callable values. Add execution and source-identity regressions for these consumers.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #904 +/- ##
==========================================
+ Coverage 95.34% 95.44% +0.10%
==========================================
Files 134 138 +4
Lines 26762 27224 +462
==========================================
+ Hits 25516 25985 +469
+ Misses 1246 1239 -7 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
I found that field Rename can infer the wrong receiver when a plain module function is stored on a class:
Python returns an
Owner, but Rope can infer anOther. RenamingOwner.fieldthen missesresult.field, while renamingOther.fieldchanges a reference that belongs toOwner. Both edits can break execution. Saving the access assaved = Owner().callbackalso loses the receiver beforesaved(Other())is analyzed.I retain the receiver in a bound access value while preserving the original function, class slot, and parameter source identities. Direct and saved instance calls use that receiver once; class access remains unbound. Inherited slots and imported module functions keep their original storage and lexical modules. Direct functions placed on the instance itself retain their unbound behavior, including writes through an alias of that instance. Overriding a different instance does not change the first instance's access.
I also pass the bound receiver to the original function during call analysis and preserve the callable and receiver in saved object records. The execution checks cover field and source-name Rename, imported parameter keyword Rename, ordinary module analysis, and reading saved call values after closing and reopening the project.
The supported storage is an unambiguous class-body name assignment of an undecorated module function with an ordinary positional parameter for the receiver and no positional-only or keyword-only parameters. Override checks examine the storage, receiver, and access modules. Arbitrary writes in other modules, decorated functions or storage classes, metaclasses, and multiple storage assignments remain outside this inference. The existing ordinary argument protocol is retained: #898 covers the separate parameter/default/staticmethod changes, #900 covers lambda source values, and #901 covers external class data writes. This change does not require those PRs or introduce a general descriptor model.
Validation
Checklist