Skip to content

impl instance method inline#2301

Closed
asukaminato0721 wants to merge 1 commit intofacebook:mainfrom
asukaminato0721:2033
Closed

impl instance method inline#2301
asukaminato0721 wants to merge 1 commit intofacebook:mainfrom
asukaminato0721:2033

Conversation

@asukaminato0721
Copy link
Copy Markdown
Contributor

@asukaminato0721 asukaminato0721 commented Feb 4, 2026

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

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Feb 4, 2026

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

@asukaminato0721 asukaminato0721 marked this pull request as ready for review February 4, 2026 17:53
Copilot AI review requested due to automatic review settings February 4, 2026 17:53
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 self references
  • 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.

@meta-codesync
Copy link
Copy Markdown
Contributor

meta-codesync Bot commented Feb 4, 2026

@kinto0 has imported this pull request. If you are a Meta employee, you can view this in D92313955.

Copy link
Copy Markdown
Contributor

@stroxler stroxler left a comment

Choose a reason for hiding this comment

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

Review automatically exported from Phabricator review in Meta.

@meta-codesync
Copy link
Copy Markdown
Contributor

meta-codesync Bot commented Feb 5, 2026

@kinto0 merged this pull request in 922f33f.

@asukaminato0721 asukaminato0721 deleted the 2033 branch February 5, 2026 18:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants