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

Bug: Formatting inconsistency with f strings #14513

Closed
jvacek opened this issue Nov 21, 2024 · 2 comments
Closed

Bug: Formatting inconsistency with f strings #14513

jvacek opened this issue Nov 21, 2024 · 2 comments
Labels
formatter Related to the formatter question Asking for support or clarification

Comments

@jvacek
Copy link
Contributor

jvacek commented Nov 21, 2024

I would assume that the second version of mystr would be formatted, but it doesn't

i = 2

# This gets formatted
sign = "+" if i > 0 else "-"
sign = "+" if i>0 else "-" # gets spaces around '>'

# This does not get formatted
mystr = f"HI {'+' if i > 0 else '-'}{i}"
mystr = f"HI {'+' if i>0 else '-'}{i}"
@MichaReiser
Copy link
Member

MichaReiser commented Nov 21, 2024

Ruff supports f-string formatting but only as a preview feature. We plan to release it early next year, once we figured out all edge cases :) You can give it a try by setting format.preview = true.

See #13371

@MichaReiser MichaReiser added question Asking for support or clarification formatter Related to the formatter labels Nov 21, 2024
@jvacek
Copy link
Contributor Author

jvacek commented Nov 21, 2024

Tried that in the meantime, you beat me to it. Thanks!

@jvacek jvacek closed this as completed Nov 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
formatter Related to the formatter question Asking for support or clarification
Projects
None yet
Development

No branches or pull requests

2 participants