Skip to content

fix add quickfix for Unnecessary str() call; #3342#3371

Open
asukaminato0721 wants to merge 1 commit into
facebook:mainfrom
asukaminato0721:3342
Open

fix add quickfix for Unnecessary str() call; #3342#3371
asukaminato0721 wants to merge 1 commit into
facebook:mainfrom
asukaminato0721:3342

Conversation

@asukaminato0721
Copy link
Copy Markdown
Contributor

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

@meta-cla meta-cla Bot added the cla signed label May 13, 2026
@asukaminato0721 asukaminato0721 marked this pull request as ready for review May 13, 2026 04:40
Copilot AI review requested due to automatic review settings May 13, 2026 04:40
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

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.

@github-actions
Copy link
Copy Markdown

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

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.

add quickfix for Unnecessary str() call;

2 participants