fix add quickfix for Unnecessary str() call; #3342#3371
Open
asukaminato0721 wants to merge 1 commit into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a local LSP quick fix for the UnnecessaryTypeConversion diagnostic so redundant conversion calls like str(x) (when x is already str) offer an actionable code action that rewrites the call to just x (Fixes #3342).
Changes:
- Added a new quick-fix implementation that replaces an unnecessary builtin conversion call with its sole argument (with parenthesization when needed).
- Wired the quick fix into the LSP code-action pipeline for
ErrorKind::UnnecessaryTypeConversion. - Added an LSP golden-style test that validates the new code action behavior for
str(x).
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
pyrefly/lib/test/lsp/code_actions.rs |
Adds a regression test asserting the new “Remove unnecessary str() call” code action and edit output. |
pyrefly/lib/state/lsp/quick_fixes/unnecessary_type_conversion.rs |
Implements the quick fix that identifies the enclosing call and replaces it with the argument expression (wrapping when necessary). |
pyrefly/lib/state/lsp/quick_fixes/mod.rs |
Exposes the new unnecessary_type_conversion quick-fix module. |
pyrefly/lib/state/lsp.rs |
Registers the new quick fix for ErrorKind::UnnecessaryTypeConversion when building local code actions. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
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
Fixes #3342
Added a local quick fix for UnnecessaryTypeConversion diagnostics so str(x) on an already-str value now offers Remove unnecessary str() call and rewrites it to x.
Test Plan
add test