Skip to content

Conversation

@asukaminato0721
Copy link
Contributor

Summary

Fixes part of #1589

microsoft/pylance-release#146

Implemented an “Implement abstract members” quick fix that derives missing abstract members via the solver, copies signatures/decorators/docstrings, and inserts stubs into the selected class, then wired it into LSP code actions.

Test Plan

added a test.

fmt
@meta-cla meta-cla bot added the cla signed label Jan 22, 2026
@asukaminato0721 asukaminato0721 changed the title impl Autocomplete Abstract, Protocol and method override #146 impl Autocomplete Abstract, Protocol and method override #1589 Jan 22, 2026
@asukaminato0721 asukaminato0721 marked this pull request as ready for review January 22, 2026 12:01
Copilot AI review requested due to automatic review settings January 22, 2026 12:01
Copy link

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 implements a "Implement abstract members" quick fix feature that automatically generates method stubs for abstract methods and protocol members. The implementation detects unimplemented abstract methods from parent classes, copies their signatures/decorators/docstrings, and inserts properly formatted stub implementations.

Changes:

  • Added new implement_abstract_members.rs module with logic to detect and generate stubs for abstract/protocol methods
  • Integrated the quick fix into LSP code actions in server.rs
  • Added comprehensive tests for abstract class members and Protocol implementations

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
pyrefly/lib/state/lsp/quick_fixes/implement_abstract_members.rs New module implementing the core logic for detecting abstract members and generating method stubs with proper signatures, decorators, and docstrings
pyrefly/lib/state/lsp/quick_fixes/mod.rs Module declaration for the new implement_abstract_members module
pyrefly/lib/state/lsp.rs Transaction method exposing the new quick fix functionality
pyrefly/lib/lsp/non_wasm/server.rs LSP integration to include implement abstract members in code actions
pyrefly/lib/alt/class/class_field.rs Changed visibility of get_class_member_with_defining_class to pub(crate) to support the new feature
pyrefly/lib/test/lsp/code_actions.rs Added test helper functions and two comprehensive tests for abstract and protocol implementations; also modified an existing test but introduced a bug with missing ABC import

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@github-actions

This comment has been minimized.

@asukaminato0721 asukaminato0721 marked this pull request as draft January 22, 2026 12:35
@asukaminato0721 asukaminato0721 marked this pull request as ready for review January 22, 2026 15:11
@github-actions

This comment has been minimized.

@github-actions
Copy link

Diff from mypy_primer, showing the effect of this PR on open source code:

openlibrary (https://github.com/internetarchive/openlibrary)
+ ERROR openlibrary/plugins/openlibrary/lists.py:811:43-813:18: Cannot set item in `dict[str, list[dict[Unknown, Unknown]]]` [unsupported-operation]
+ ERROR openlibrary/plugins/openlibrary/lists.py:818:40-88: Cannot set item in `dict[str, list[dict[Unknown, Unknown]]]` [unsupported-operation]
+ ERROR openlibrary/plugins/openlibrary/lists.py:823:42-825:18: Cannot set item in `dict[str, list[dict[Unknown, Unknown]]]` [unsupported-operation]
+ ERROR openlibrary/plugins/upstream/tests/test_merge_authors.py:142:12-52: Object of class `NoneType` has no attribute `key` [missing-attribute]
+ ::error file=openlibrary/plugins/openlibrary/lists.py,line=811,col=43,endLine=813,endColumn=18,title=Pyrefly unsupported-operation::Cannot set item in `dict[str, list[dict[Unknown, Unknown]]]`%0A  Argument `list[Thing | Unknown]` is not assignable to parameter `value` with type `list[dict[Unknown, Unknown]]` in function `dict.__setitem__`
+ ::error file=openlibrary/plugins/openlibrary/lists.py,line=818,col=40,endLine=818,endColumn=88,title=Pyrefly unsupported-operation::Cannot set item in `dict[str, list[dict[Unknown, Unknown]]]`%0A  Argument `list[Thing | Unknown]` is not assignable to parameter `value` with type `list[dict[Unknown, Unknown]]` in function `dict.__setitem__`
+ ::error file=openlibrary/plugins/openlibrary/lists.py,line=823,col=42,endLine=825,endColumn=18,title=Pyrefly unsupported-operation::Cannot set item in `dict[str, list[dict[Unknown, Unknown]]]`%0A  Argument `list[Thing | Unknown]` is not assignable to parameter `value` with type `list[dict[Unknown, Unknown]]` in function `dict.__setitem__`
- ::error file=openlibrary/plugins/upstream/tests/test_merge_authors.py,line=37,col=9,endLine=37,endColumn=12,title=Pyrefly bad-override::Class member `MockSite.get` overrides parent class `Site` in an inconsistent manner%0A  `MockSite.get` has type `BoundMethod[MockSite, (self: MockSite, key: Unknown) -> Unknown]`, which is not assignable to `BoundMethod[MockSite, (self: MockSite, key: Unknown, revision: Unknown | None = None, lazy: bool | Unknown = False) -> Unknown | None]`, the type of `Site.get`
+ ::error file=openlibrary/plugins/upstream/tests/test_merge_authors.py,line=37,col=9,endLine=37,endColumn=12,title=Pyrefly bad-override::Class member `MockSite.get` overrides parent class `Site` in an inconsistent manner%0A  `MockSite.get` has type `BoundMethod[MockSite, (self: MockSite, key: Unknown) -> Thing | Unknown]`, which is not assignable to `BoundMethod[MockSite, (self: MockSite, key: Unknown, revision: Unknown | None = None, lazy: bool | Unknown = False) -> Thing | Unknown | None]`, the type of `Site.get`
+ ::error file=openlibrary/plugins/upstream/tests/test_merge_authors.py,line=142,col=12,endLine=142,endColumn=52,title=Pyrefly missing-attribute::Object of class `NoneType` has no attribute `key`

@mohaidoss
Copy link

Up we need this <3

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.

2 participants