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

Indent multi-line expressions in function arguments #12854

Closed
edaqa-uncountable opened this issue Aug 13, 2024 · 1 comment
Closed

Indent multi-line expressions in function arguments #12854

edaqa-uncountable opened this issue Aug 13, 2024 · 1 comment
Labels
formatter Related to the formatter needs-decision Awaiting a decision from a maintainer style How should formatted code look

Comments

@edaqa-uncountable
Copy link

edaqa-uncountable commented Aug 13, 2024

Would it be possible to add an option to allow indentation of multi-line expressions in function arguments? Currently it aligns everything to the left with the other arguments.

For example, this is the formatting I get:

some_func(
   param_one=value,
   param_two="hi"
   if some_cond
   else "bye",
   param_three=1
   if some_cond
   else 2,
)

That alignment is hard to read. I want something like this instead:

some_func(
   param_one=value,
   param_two="hi"
       if some_cond
       else "bye",
   param_three=1
       if some_cond
       else 2,
)

I've shortened the lines to focus on the alignment (though I realize this short they might end up on one-line)

I admit I don't know what the ideal formatting here is, but the first one is definitely not it. Perhaps it should always rewrite as a paren expression, which has nicer results.

some_func(
   param_one=value,
   param_two=(
       "hi"
       if some_cond
       else "bye"
   ),
   param_three=(
       1
       if some_cond
       else 2
   )
)

Keywords: indent function argument parameter

@dhruvmanila dhruvmanila added formatter Related to the formatter needs-decision Awaiting a decision from a maintainer style How should formatted code look labels Aug 13, 2024
@MichaReiser
Copy link
Member

I agree, that Ruff's current nested expression formatting isn't ideal (for example, the formatting of the if else expression) and I explained my thinking around it in psf/black#4123 (and why we deviate from black).

We plan to revisit sub-expression formatting. I just created #12856 to make this more visible.

Therefore, yes we want to improve nested if expression formatting although I'm not sure if it will use the exact style that you're proposing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
formatter Related to the formatter needs-decision Awaiting a decision from a maintainer style How should formatted code look
Projects
None yet
Development

No branches or pull requests

3 participants