-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Formatter undocumented deviation: Formatting of long lambda as keyword argument #8179
Comments
Thanks! |
This seems possibly related https://play.ruff.rs/c9b4e3fa-4401-4248-a98d-d9ae6b984697?secondary=Format |
Yeah, looks like we have some refinements to make in the lambda formatting. On it! (Thanks for sharing playground links, it helps a lot.) |
@charliermarsh Can i take this issue up? |
@DarthMuzammil sure. Let me know if you need any help |
@DarthMuzammil -- have you had a chance to look into this? If not, do you still plan to? (No pressure, I just want to make sure we find an owner soon if it's not being addressed.) |
It seems black never inserts soft line breaks between parameters. This would be an easy fix... except for comments Although Black's formatting also has its shortcomings when you have default values: def a():
return b(
c,
d,
e,
f=lambda self, araa, kkkwargs=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(
*args, **kwargs
), e=1, f=2, g=2: d,
) It could be nice to simply parenthesize the lambda expression and indent it by 1 level (and otherwise keep our formatting). However, that would also mean that the formatter must remove the parentheses again when the lambda fits on a single line—something we haven't really done before in sub-expression positions. And there's also no real good place to add it, because this should be done when formatting lambas in any position. |
@charliermarsh Hey, sorry for the delay i just saw this message, yes i will start working on this today |
@MichaReiser How should i go about solving this issue? |
@DarthMuzammil not sure. I think coming up with a style that works with the presence of comments (which black does not always) is the main work of this issue. My preferred solution would be to just parenthesize the lambda parameters if it breaks, but Python3 removed support for parenthesized lambda parameters for some reason :( # Using parentheses is a syntax error
def a():
return b(
c,
d,
e,
f=lambda (
self,
araa,
kkkwargs=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(
*args, **kwargs
),
e=1,
f=2,
g=2
): d,
) Related black issue: psf/black#809 |
Black formatting:
Ruff formatting:
In addition to being incompatible, this formatting seems very strange and not very readable, as the
*args
and**kwargs
suddenly look like they are arguments tob
.The text was updated successfully, but these errors were encountered: