[New Rule] Replace f-string without any text with using value directly instead
See original GitHub issueExplanation
Analyze f-strings. If f-string has no text and only a passed value, then use that value directly.
Example 1
# Bad
foo = "bar"
my_text = f"{foo}"
# Good
foo = "bar"
my_text = foo
Example 2
# Bad
def my_func(foo: str):
my_text = f"{foo}"
# Good
def my_func(foo: str):
my_text = foo
Example 3
# Bad
my_number = 123
my_text = f"{foo}"
# Good
my_number = 123
my_text = str(foo)
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:7 (4 by maintainers)
Top Results From Across the Web
Search and replacing strings without using Regex but loops ...
I found a way to do string search and replace without using Regex but when I want to replace more than one instance...
Read more >Using Excel REPLACE and SUBSTITUTE functions - Ablebits
An Excel REPLACE formula always returns a text string, not number. In the screenshot above, notice the left alignment of the returned text...
Read more >SUBSTITUTE function - Microsoft Support
Use SUBSTITUTE when you want to replace specific text in a text string; use REPLACE when you want to replace any text that...
Read more >How to Replace a String in Python
In Python, the .replace() method and the re.sub() function are often used to clean up text by removing strings or substrings or replacing...
Read more >SUBSTITUTE - Google Docs Editors Help
Replaces existing text with new text in a string. ... If a number is desired, try using the VALUE function in conjunction with...
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 Free
Top 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

Aparently f-strings are
ast.JoinedStrand the parameters are automatically parsed. Variables areast.FormattedValue. So we can recognize when we have an f-string.You are right. Probably no type checking is required.