black icon indicating copy to clipboard operation
black copied to clipboard

[style] Function default parameters - ugly lambda explosion

Open Starwort opened this issue 3 years ago • 0 comments

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 avatar Dec 12 '22 05:12 Starwort