Closed
Conversation
|
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
There was a problem hiding this comment.
Pull request overview
This PR enhances the inline method refactoring feature (introduced in #2033) to support instance methods within classes. Previously, the inline method refactoring only worked for module-level functions; now it also handles method calls like self.foo() within class contexts.
Changes:
- Added fallback logic to find method definitions when symbol resolution fails for instance method calls
- Implemented AST traversal helpers to locate the enclosing method and resolve
selfreferences - Added test coverage for the basic class method inline scenario
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| pyrefly/lib/state/lsp/quick_fixes/inline_method.rs | Adds find_enclosing_method and find_method_def_for_self_call helper functions to handle instance method resolution, and updates the main code action logic to fall back to AST-based method lookup when symbol resolution fails |
| pyrefly/lib/test/lsp/code_actions.rs | Adds test case inline_method_for_class to verify that instance methods can be inlined when called via self.foo() |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Contributor
stroxler
approved these changes
Feb 5, 2026
Contributor
stroxler
left a comment
There was a problem hiding this comment.
Review automatically exported from Phabricator review in Meta.
Contributor
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.
Summary
enhancement for #2033
find that class method is missing support
Implemented class instance method inline support by adding an AST-based fallback when find_definition can’t resolve self.foo();
it now resolves to the method in the same enclosing class only when the receiver matches the enclosing method’s first parameter and the enclosing method isn’t
@staticmethod/@classmethod.Test Plan
add test