rope icon indicating copy to clipboard operation
rope copied to clipboard

Inlining string constant into f-string should be smarter

Open lieryan opened this issue 4 years ago • 0 comments

Describe the bug

Inlining expression containing string constant into f-string should take into consideration the surrounding f-string's quote.

To Reproduce Steps to reproduce the behavior:

  1. Code before refactoring:
msg = "hello"
s = f"foo: {msg}"
  1. Inline "msg"

  2. Expected code after refactoring, should be either:

s = f"foo: {'hello'}"

or maybe even special case the situation where

s = f"foo: hello"
  1. Describe the error or unexpected result that you are getting
s = f"foo: {"hello"}"

which is not a valid code because the double quotes cannot be parsed properly by Python:

SyntaxError: f-string: expecting '}'

Editor information (please complete the following information):

  • Project Python version: 3.9.5
  • Rope Python version: 0.9.5
  • Rope version: 0.20.1

lieryan avatar Oct 07 '21 12:10 lieryan