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

Scientific notation formatter misses f-strings #9083

Closed
claydugo opened this issue Dec 11, 2023 · 2 comments
Closed

Scientific notation formatter misses f-strings #9083

claydugo opened this issue Dec 11, 2023 · 2 comments

Comments

@claydugo
Copy link

Sorry for not listing the actual rule.
I tried all the flags in ruff format --help but never got an output that explains which rule is making the change.

I can update the title if pointed to which is doing it. Also is there a command I missed that outputs this? --show-fixes seems to be only a linter flag.

Reproduce:

int_variable = 3

fstring1 = f"This string contains scientific notation. {int_variable * 1E-3}"
fstring2 = f"string containing scientific notation. {int_variable * 1E3:.2f}"

variable_notation1 = 1E3
variable_notation2 = (int_variable * 1E-3)

Output of ruff format --diff

--- example.py
+++ example.py
@@ -3,5 +3,5 @@
 fstring1 = f"This string contains scientific notation. {int_variable * 1E-3}"
 fstring2 = f"string containing scientific notation. {int_variable * 1E3:.2f}"

-variable_notation1 = 1E3
-variable_notation2 = (int_variable * 1E-3)
+variable_notation1 = 1e3
+variable_notation2 = int_variable * 1e-3

1 file would be reformatted
@MichaReiser
Copy link
Member

Hy @claydugo

There's no specific rule that performs this change. Instead, the formatter normalizes the scientific notation to consistently use the lowercase `e. So, there's no rule that you need to enable or disable.

However, your observation is correct. The formatter doesn't format expressions inside f-strings yet (similar to black). @dhruvmanila started working on formatting expressions inside of f-strings, which should give you the desired behavior (including splitting expressions to make the f-string fit if possible).

@claydugo claydugo changed the title Scientific Notation formatter misses f-strings Scientific notation formatter misses f-strings Dec 11, 2023
@dhruvmanila
Copy link
Member

Hey, thanks for the issue and thanks Micha for providing the context. I'll close this in favor of #7594 which tracks f-string formatting.

@dhruvmanila dhruvmanila closed this as not planned Won't fix, can't repro, duplicate, stale Dec 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants