-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Should Black change .format()
and %
into f-strings in 3.6+ mode?
#363
Comments
This is a nice idea but I feel it's out of scope for Black. Black is not a linter, it's a formatter. It starts and ends with the same AST. I'll think about it, in the mean time Anthony's pyupgrade seems like a good tool that feels this need. |
.format()
and %
into f-strings in 3.6+ mode?
I'm all for more f-strings, but I also think that it is out of the scope for black to do the conversion. |
Such converting can be harmful. For example, this code works well:
But it's very difficult to replace |
Black would (if it ever did this) only do it for calls to |
I was going to open an issue for this, but I saw that it already existed. In my opinion f-strings are also about format. A f-string is much easier to read and understand that the old strings so it would be awesome if Black could make this changes automatically. |
Please don't make black too smart by auto upgrading code. I'm just looking through issues to get an idea of where black is heading and plan to start using black on projects when it has a stable release. Suggestions like this makes me feel a bit uneasy. I believe that it's good if all AST modifying features were turned off by default and enabled via 'pyproject.toml` or not added at all. |
While I agree that |
Via code review :) |
I think we can see this as rejected for understandable reasons. |
I know this issue is closed, but I'll comment on it in case someone ever finds it while doing research. First off, I agree this is out of scope for Second, converting For example, consider: Okay, I'll touch on another problem: subscripting is treated differently:
There are other nuances to the subscript problem as well, such as whether a subscript "looks like" a number, and just what "looks like" means. |
@ambv You might wanna remove this from the corresponding project board. :) |
For Python3.6+ formatting, I would really like to see black convert all formatted strings to f-strings if possible.
F-strings are shorter, easier to read and, in my opinion, more pythonic.
The text was updated successfully, but these errors were encountered: