convert f-string with nothing to interpolate to regular string
See original GitHub issueIs your feature request related to a problem? Please describe.
f-strings are great. sometimes they are so great we might use them even when we don’t need to, such as in files where an f-string is used but nothing to interpolate was included in the string body.
Describe the solution you’d like
say you had a python script with a line like this:
hello = f"hello"
black should see that f-string, recognize that it could just be a regular string and drop the f-prefix.
output:
hello = "hello"
Describe alternatives you’ve considered
Could return an error message, but I want black to format for me. Could also not do this, but I think changing to a regular string is a better option.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:15
- Comments:8 (4 by maintainers)
Top Results From Across the Web
string interpolation - format string output - Microsoft Learn
To identify a string literal as an interpolated string, prepend it with the $ symbol. You can't have any white space between the...
Read more >how I convert string into interpolated string? - Stack Overflow
Find & replace can stil be used with a regex. You could use an object instead of seperate variables with the data you...
Read more >Python String Interpolation - Programiz
String interpolation is a process substituting values of variables into placeholders in a string. For instance, if you have a template for saying...
Read more >Python String Interpolation - Towards Data Science
String interpolation is a process of injecting value into a placeholder (a placeholder is nothing but a variable to which you can assign ......
Read more >Python String Formatting Best Practices
Learn the four main approaches to string formatting in Python, ... #3 String Interpolation / f-Strings (Python 3.6+); #4 Template Strings (Standard Library) ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Half the time I forget to add the
f
prefix. The other half the time I forget to add the curly brackets around my var. I think automatically dropping a “looks useless to me”f
prefix is a bad idea. How canblack
know what the user intended?The same argument applies to the "automatically add
f
prefix.Sorry, but 👎 for me.
This can potentially be dangerous for f-strings with brackets.