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

[style] Function default parameters - ugly lambda explosion #3432

Open
Starwort opened this issue Dec 12, 2022 · 1 comment
Open

[style] Function default parameters - ugly lambda explosion #3432

Starwort opened this issue Dec 12, 2022 · 1 comment
Labels
F: linebreak How should we split up lines? T: style What do we want Blackened code to look like?

Comments

@Starwort
Copy link

Describe the style change

Lambdas used as default parameters for functions look really ugly when the function parameter is exploded (e.g. via a typehint being too long

Examples in the current Black style

class Foo:
    def bar(
        self,
        baz: typing.Callable[
            # long typevar name (and this comment) causes
            # declaration to be exploded
            [SpecialisationT, SpecialisationT], SpecialisationT
        ] = lambda i, j: j
        - i,  # ugly line split here
    ):
        ...

Desired style

class Foo:
    def bar(
        self,
        baz: typing.Callable[
            [SpecialisationT, SpecialisationT], SpecialisationT
        ] = lambda i, j: j - i,  # no ugly line split
    ):
        ...

Additional context

The formatting issue can be sidestepped with a pair of brackets around the lambda, so not top priority, but this is uncharacteristically bad formatting

@Starwort Starwort added the T: style What do we want Blackened code to look like? label Dec 12, 2022
@felix-hilden felix-hilden added the F: linebreak How should we split up lines? label Jan 29, 2023
@felix-hilden
Copy link
Collaborator

All for it. And I'd like to see the lambda on a separate line depending on which element violates the line length first. (playground examples)

typing.Callable[
    ReallyStupidlyLongTypeVariableThatIsPracticallyNeverendingAndGoesOverLineLenght
] = (lambda i, j: j - i)
# parens prolly useless above too

typing.Callable[ReallyStupidlyLongTypeVariableThatIsPracticallyNeverending] = (
    lambda i, j: j - i
)

def bar(
    baz: typing.Callable[QuiteLengthyTypeVariable] = (
        lambda withmuchlonger, argumentnameshere: withmuchlonger - argumentnameshere
    ),
):
    ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F: linebreak How should we split up lines? T: style What do we want Blackened code to look like?
Projects
None yet
Development

No branches or pull requests

2 participants