Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace f-strings with regular strings #3081

Closed
KAction opened this issue May 21, 2022 · 6 comments
Closed

Replace f-strings with regular strings #3081

KAction opened this issue May 21, 2022 · 6 comments
Labels
F: strings Related to our handling of strings

Comments

@KAction
Copy link

KAction commented May 21, 2022

Often as result of refactoring I end up with f-string with no
{substitutions}, and my editor (integrated with flake8) keeps
reminding me about it.

With some stretch one can argue that this is actually formatting issue
and as such within scope of black(1). Would you be interested in patch
that implement this proposal?

print(f"Hello")

to become

print("Hello")
@JelleZijlstra JelleZijlstra added the F: strings Related to our handling of strings label May 21, 2022
@JelleZijlstra
Copy link
Collaborator

Preview mode does this in some cases but not here. I agree that it's worthwhile, although it does change Python's AST.

@PBNMH22
Copy link

PBNMH22 commented May 21, 2022

Hi I am new to this, I was searching for this but the code base is huge.
Request you to please navigate me to desired file or folder.
I will try my best.

@KAction
Copy link
Author

KAction commented May 21, 2022

I think it is as simple as dropping drop_useless_fstring conditional. I'd like to grab lock on this issue for coming 72 hours. I'll do my best to come with PR within this timeframe.

@SUDDSDUDDS

This comment was marked as off-topic.

@JelleZijlstra
Copy link
Collaborator

@graingert (responding to your comment on #3087, where I'd like the focus to stay on the broader propsal). This does change the AST:

>>> ast.dump(ast.parse('f"x"'))
"Module(body=[Expr(value=JoinedStr(values=[Constant(value='x')]))], type_ignores=[])"
>>> ast.dump(ast.parse('"x"'))
"Module(body=[Expr(value=Constant(value='x'))], type_ignores=[])"

@JelleZijlstra
Copy link
Collaborator

Duplicate of #1156

@JelleZijlstra JelleZijlstra marked this as a duplicate of #1156 May 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F: strings Related to our handling of strings
Projects
None yet
Development

No branches or pull requests

4 participants