Keep lambda parameters on one line and parenthesize the body if it expands by ntBre · Pull Request #21385 · astral-sh/ruff (original) (raw)

@ntBre added formatter

Related to the formatter

preview

Related to preview mode features

labels

Nov 11, 2025

ntBre

ntBre added a commit that referenced this pull request

Nov 11, 2025

@ntBre

ntBre

@ntBre ntBre changed the title[WIP] Indent lambda parameters if parameters wrap [WIP] Keep lambda parameters on one line and parenthesize the body if it expands

Nov 12, 2025

@ntBre ntBre changed the title[WIP] Keep lambda parameters on one line and parenthesize the body if it expands Keep lambda parameters on one line and parenthesize the body if it expands

Nov 14, 2025

@ntBre ntBre marked this pull request as ready for review

November 14, 2025 13:54

MichaReiser

MichaReiser

@ntBre ntBre marked this pull request as draft

November 18, 2025 19:15

ntBre added a commit that referenced this pull request

Nov 20, 2025

@ntBre

Summary

This PR changes our formatting of lambda expressions to keep the parameters on a single line, at least if there are no comments. This fixes #8179.

Black formatting and this PR's formatting:

def a():
    return b(
        c,
        d,
        e,
        f=lambda self, *args, **kwargs: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(
            *args, **kwargs
        ),
    )

Stable Ruff formatting

def a():
    return b(
        c,
        d,
        e,
        f=lambda self,
        *args,
        **kwargs: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(*args, **kwargs),
    )

I split this off from #21385 because it seemed like the simpler change and helpful to isolate from the body parenthesization ecosystem and performance changes. However, as Micha pointed out, we need the formatting from #21385 to land first, so this branch is currently stacked on that one.

Test Plan

New formatting on tests from #8465 and #21385

MichaReiser

@ntBre

@ntBre ntBre deleted the brent/indent-lambda-params branch

December 12, 2025 17:02

dcreager added a commit that referenced this pull request

Dec 13, 2025

@dcreager

This was referenced

Feb 9, 2026

nicopauss pushed a commit to Intersec/lib-common that referenced this pull request

Apr 1, 2026

@renovate-bot @LpZ-squall

Note this update introcudes the new warning ISC004, which requires some fixes in our code.

Released on 2026-01-22.

curl --proto '=https' --tlsv1.2 -LsSf https://github.com/astral-sh/ruff/releases/download/0.14.14/ruff-installer.sh | sh
powershell -ExecutionPolicy Bypass -c "irm https://github.com/astral-sh/ruff/releases/download/0.14.14/ruff-installer.ps1 | iex"
File Platform Checksum
ruff-aarch64-apple-darwin.tar.gz Apple Silicon macOS checksum
ruff-x86_64-apple-darwin.tar.gz Intel macOS checksum
ruff-aarch64-pc-windows-msvc.zip ARM64 Windows checksum
ruff-i686-pc-windows-msvc.zip x86 Windows checksum
ruff-x86_64-pc-windows-msvc.zip x64 Windows checksum
ruff-aarch64-unknown-linux-gnu.tar.gz ARM64 Linux checksum
ruff-i686-unknown-linux-gnu.tar.gz x86 Linux checksum
ruff-powerpc64-unknown-linux-gnu.tar.gz PPC64 Linux checksum
ruff-powerpc64le-unknown-linux-gnu.tar.gz PPC64LE Linux checksum
ruff-riscv64gc-unknown-linux-gnu.tar.gz RISCV Linux checksum
ruff-s390x-unknown-linux-gnu.tar.gz S390x Linux checksum
ruff-x86_64-unknown-linux-gnu.tar.gz x64 Linux checksum
ruff-armv7-unknown-linux-gnueabihf.tar.gz ARMv7 Linux checksum
ruff-aarch64-unknown-linux-musl.tar.gz ARM64 MUSL Linux checksum
ruff-i686-unknown-linux-musl.tar.gz x86 MUSL Linux checksum
ruff-x86_64-unknown-linux-musl.tar.gz x64 MUSL Linux checksum
ruff-arm-unknown-linux-musleabihf.tar.gz ARMv6 MUSL Linux (Hardfloat) checksum
ruff-armv7-unknown-linux-musleabihf.tar.gz ARMv7 MUSL Linux checksum

Released on 2026-01-15.

This is a follow-up release to 0.14.12. Because of an issue publishing the WASM packages, there is no GitHub release or Git tag for 0.14.12, although the package was published to PyPI. The contents of the 0.14.13 release are identical to 0.14.12.

curl --proto '=https' --tlsv1.2 -LsSf https://github.com/astral-sh/ruff/releases/download/0.14.13/ruff-installer.sh | sh
powershell -ExecutionPolicy Bypass -c "irm https://github.com/astral-sh/ruff/releases/download/0.14.13/ruff-installer.ps1 | iex"
File Platform Checksum
ruff-aarch64-apple-darwin.tar.gz Apple Silicon macOS checksum
ruff-x86_64-apple-darwin.tar.gz Intel macOS checksum
ruff-aarch64-pc-windows-msvc.zip ARM64 Windows checksum
ruff-i686-pc-windows-msvc.zip x86 Windows checksum
ruff-x86_64-pc-windows-msvc.zip x64 Windows checksum
ruff-aarch64-unknown-linux-gnu.tar.gz ARM64 Linux checksum
ruff-i686-unknown-linux-gnu.tar.gz x86 Linux checksum
ruff-powerpc64-unknown-linux-gnu.tar.gz PPC64 Linux checksum
ruff-powerpc64le-unknown-linux-gnu.tar.gz PPC64LE Linux checksum
ruff-riscv64gc-unknown-linux-gnu.tar.gz RISCV Linux checksum
ruff-s390x-unknown-linux-gnu.tar.gz S390x Linux checksum
ruff-x86_64-unknown-linux-gnu.tar.gz x64 Linux checksum
ruff-armv7-unknown-linux-gnueabihf.tar.gz ARMv7 Linux checksum
ruff-aarch64-unknown-linux-musl.tar.gz ARM64 MUSL Linux checksum
ruff-i686-unknown-linux-musl.tar.gz x86 MUSL Linux checksum
ruff-x86_64-unknown-linux-musl.tar.gz x64 MUSL Linux checksum
ruff-arm-unknown-linux-musleabihf.tar.gz ARMv6 MUSL Linux (Hardfloat) checksum
ruff-armv7-unknown-linux-musleabihf.tar.gz ARMv7 MUSL Linux checksum

Released on 2026-01-08.

curl --proto '=https' --tlsv1.2 -LsSf https://github.com/astral-sh/ruff/releases/download/0.14.11/ruff-installer.sh | sh
powershell -ExecutionPolicy Bypass -c "irm https://github.com/astral-sh/ruff/releases/download/0.14.11/ruff-installer.ps1 | iex"
File Platform Checksum
ruff-aarch64-apple-darwin.tar.gz Apple Silicon macOS checksum
ruff-x86_64-apple-darwin.tar.gz Intel macOS checksum
ruff-aarch64-pc-windows-msvc.zip ARM64 Windows checksum
ruff-i686-pc-windows-msvc.zip x86 Windows checksum
ruff-x86_64-pc-windows-msvc.zip x64 Windows checksum
ruff-aarch64-unknown-linux-gnu.tar.gz ARM64 Linux checksum
ruff-i686-unknown-linux-gnu.tar.gz x86 Linux checksum
ruff-powerpc64-unknown-linux-gnu.tar.gz PPC64 Linux checksum
ruff-powerpc64le-unknown-linux-gnu.tar.gz PPC64LE Linux checksum
ruff-riscv64gc-unknown-linux-gnu.tar.gz RISCV Linux checksum
ruff-s390x-unknown-linux-gnu.tar.gz S390x Linux checksum
ruff-x86_64-unknown-linux-gnu.tar.gz x64 Linux checksum
ruff-armv7-unknown-linux-gnueabihf.tar.gz ARMv7 Linux checksum
ruff-aarch64-unknown-linux-musl.tar.gz ARM64 MUSL Linux checksum
ruff-i686-unknown-linux-musl.tar.gz x86 MUSL Linux checksum
ruff-x86_64-unknown-linux-musl.tar.gz x64 MUSL Linux checksum
ruff-arm-unknown-linux-musleabihf.tar.gz ARMv6 MUSL Linux (Hardfloat) checksum
ruff-armv7-unknown-linux-musleabihf.tar.gz ARMv7 MUSL Linux checksum

Released on 2025-12-18.

curl --proto '=https' --tlsv1.2 -LsSf https://github.com/astral-sh/ruff/releases/download/0.14.10/ruff-installer.sh | sh
powershell -ExecutionPolicy Bypass -c "irm https://github.com/astral-sh/ruff/releases/download/0.14.10/ruff-installer.ps1 | iex"
File Platform Checksum
ruff-aarch64-apple-darwin.tar.gz Apple Silicon macOS checksum
ruff-x86_64-apple-darwin.tar.gz Intel macOS checksum
ruff-aarch64-pc-windows-msvc.zip ARM64 Windows checksum
ruff-i686-pc-windows-msvc.zip x86 Windows checksum
ruff-x86_64-pc-windows-msvc.zip x64 Windows checksum
ruff-aarch64-unknown-linux-gnu.tar.gz ARM64 Linux checksum
ruff-i686-unknown-linux-gnu.tar.gz x86 Linux checksum
ruff-powerpc64-unknown-linux-gnu.tar.gz PPC64 Linux checksum
ruff-powerpc64le-unknown-linux-gnu.tar.gz PPC64LE Linux checksum
ruff-riscv64gc-unknown-linux-gnu.tar.gz RISCV Linux checksum
ruff-s390x-unknown-linux-gnu.tar.gz S390x Linux checksum
ruff-x86_64-unknown-linux-gnu.tar.gz x64 Linux checksum
ruff-armv7-unknown-linux-gnueabihf.tar.gz ARMv7 Linux checksum
ruff-aarch64-unknown-linux-musl.tar.gz ARM64 MUSL Linux checksum
ruff-i686-unknown-linux-musl.tar.gz x86 MUSL Linux checksum
ruff-x86_64-unknown-linux-musl.tar.gz x64 MUSL Linux checksum
ruff-arm-unknown-linux-musleabihf.tar.gz ARMv6 MUSL Linux (Hardfloat) checksum
ruff-armv7-unknown-linux-musleabihf.tar.gz ARMv7 MUSL Linux checksum

Released on 2025-12-11.

curl --proto '=https' --tlsv1.2 -LsSf https://github.com/astral-sh/ruff/releases/download/0.14.9/ruff-installer.sh | sh
powershell -ExecutionPolicy Bypass -c "irm https://github.com/astral-sh/ruff/releases/download/0.14.9/ruff-installer.ps1 | iex"
File Platform Checksum
ruff-aarch64-apple-darwin.tar.gz Apple Silicon macOS checksum
ruff-x86_64-apple-darwin.tar.gz Intel macOS checksum
ruff-aarch64-pc-windows-msvc.zip ARM64 Windows checksum
ruff-i686-pc-windows-msvc.zip x86 Windows checksum
ruff-x86_64-pc-windows-msvc.zip x64 Windows checksum
ruff-aarch64-unknown-linux-gnu.tar.gz ARM64 Linux checksum
ruff-i686-unknown-linux-gnu.tar.gz x86 Linux checksum
ruff-powerpc64-unknown-linux-gnu.tar.gz PPC64 Linux checksum
ruff-powerpc64le-unknown-linux-gnu.tar.gz PPC64LE Linux checksum
ruff-riscv64gc-unknown-linux-gnu.tar.gz RISCV Linux checksum
ruff-s390x-unknown-linux-gnu.tar.gz S390x Linux checksum
ruff-x86_64-unknown-linux-gnu.tar.gz x64 Linux checksum
ruff-armv7-unknown-linux-gnueabihf.tar.gz ARMv7 Linux checksum
ruff-aarch64-unknown-linux-musl.tar.gz ARM64 MUSL Linux checksum
ruff-i686-unknown-linux-musl.tar.gz x86 MUSL Linux checksum
ruff-x86_64-unknown-linux-musl.tar.gz x64 MUSL Linux checksum
ruff-arm-unknown-linux-musleabihf.tar.gz ARMv6 MUSL Linux (Hardfloat) checksum
ruff-armv7-unknown-linux-musleabihf.tar.gz ARMv7 MUSL Linux checksum

Released on 2025-12-04.

curl --proto '=https' --tlsv1.2 -LsSf https://github.com/astral-sh/ruff/releases/download/0.14.8/ruff-installer.sh | sh
powershell -ExecutionPolicy Bypass -c "irm https://github.com/astral-sh/ruff/releases/download/0.14.8/ruff-installer.ps1 | iex"
File Platform Checksum
ruff-aarch64-apple-darwin.tar.gz Apple Silicon macOS checksum
ruff-x86_64-apple-darwin.tar.gz Intel macOS checksum
ruff-aarch64-pc-windows-msvc.zip ARM64 Windows checksum
ruff-i686-pc-windows-msvc.zip x86 Windows checksum
ruff-x86_64-pc-windows-msvc.zip x64 Windows checksum
ruff-aarch64-unknown-linux-gnu.tar.gz ARM64 Linux checksum
ruff-i686-unknown-linux-gnu.tar.gz x86 Linux checksum
ruff-powerpc64-unknown-linux-gnu.tar.gz PPC64 Linux checksum
ruff-powerpc64le-unknown-linux-gnu.tar.gz PPC64LE Linux checksum
ruff-riscv64gc-unknown-linux-gnu.tar.gz RISCV Linux checksum
ruff-s390x-unknown-linux-gnu.tar.gz S390x Linux checksum
ruff-x86_64-unknown-linux-gnu.tar.gz x64 Linux checksum
ruff-armv7-unknown-linux-gnueabihf.tar.gz ARMv7 Linux checksum
ruff-aarch64-unknown-linux-musl.tar.gz ARM64 MUSL Linux checksum
ruff-i686-unknown-linux-musl.tar.gz x86 MUSL Linux checksum
ruff-x86_64-unknown-linux-musl.tar.gz x64 MUSL Linux checksum
ruff-arm-unknown-linux-musleabihf.tar.gz ARMv6 MUSL Linux (Hardfloat) checksum
ruff-armv7-unknown-linux-musleabihf.tar.gz ARMv7 MUSL Linux checksum

Released on 2025-11-28.

curl --proto '=https' --tlsv1.2 -LsSf https://github.com/astral-sh/ruff/releases/download/0.14.7/ruff-installer.sh | sh
powershell -ExecutionPolicy Bypass -c "irm https://github.com/astral-sh/ruff/releases/download/0.14.7/ruff-installer.ps1 | iex"
File Platform Checksum
ruff-aarch64-apple-darwin.tar.gz Apple Silicon macOS checksum
ruff-x86_64-apple-darwin.tar.gz Intel macOS checksum
ruff-aarch64-pc-windows-msvc.zip ARM64 Windows checksum
ruff-i686-pc-windows-msvc.zip x86 Windows checksum
ruff-x86_64-pc-windows-msvc.zip x64 Windows checksum
ruff-aarch64-unknown-linux-gnu.tar.gz ARM64 Linux checksum
ruff-i686-unknown-linux-gnu.tar.gz x86 Linux checksum
ruff-powerpc64-unknown-linux-gnu.tar.gz PPC64 Linux checksum
ruff-powerpc64le-unknown-linux-gnu.tar.gz PPC64LE Linux checksum
ruff-riscv64gc-unknown-linux-gnu.tar.gz RISCV Linux checksum
ruff-s390x-unknown-linux-gnu.tar.gz S390x Linux checksum
ruff-x86_64-unknown-linux-gnu.tar.gz x64 Linux checksum
ruff-armv7-unknown-linux-gnueabihf.tar.gz ARMv7 Linux checksum
ruff-aarch64-unknown-linux-musl.tar.gz ARM64 MUSL Linux checksum
ruff-i686-unknown-linux-musl.tar.gz x86 MUSL Linux checksum
ruff-x86_64-unknown-linux-musl.tar.gz x64 MUSL Linux checksum
ruff-arm-unknown-linux-musleabihf.tar.gz ARMv6 MUSL Linux (Hardfloat) checksum
ruff-armv7-unknown-linux-musleabihf.tar.gz ARMv7 MUSL Linux checksum

Released on 2025-11-21.

curl --proto '=https' --tlsv1.2 -LsSf https://github.com/astral-sh/ruff/releases/download/0.14.6/ruff-installer.sh | sh
powershell -ExecutionPolicy Bypass -c "irm https://github.com/astral-sh/ruff/releases/download/0.14.6/ruff-installer.ps1 | iex"
File Platform Checksum
ruff-aarch64-apple-darwin.tar.gz Apple Silicon macOS checksum
ruff-x86_64-apple-darwin.tar.gz Intel macOS checksum
ruff-aarch64-pc-windows-msvc.zip ARM64 Windows checksum
ruff-i686-pc-windows-msvc.zip x86 Windows [checksum](https://github.com/astral-sh/ruff/releases/download/0.14.6/ru…

nicopauss pushed a commit to Intersec/lib-common that referenced this pull request

Apr 1, 2026

@renovate-bot @nicopauss

Released on 2026-03-19.

Released on 2026-03-12.

Released on 2026-03-05.

Released on 2026-02-26.

This is a follow-up release to 0.15.3 that resolves a panic when the new rule PLR1712 was enabled with any rule that analyzes definitions, such as many of the ANN or D rules.

Released on 2026-02-26.

Released on 2026-02-19.

Released on 2026-02-12.

Released on 2026-02-03.

Check out the blog post for a migration guide and overview of the changes!

The following rules have been stabilized and are no longer in preview:

The following behaviors have been stabilized:

This release introduces the new 2026 style guide, with the following changes:

Renovate-Branch: renovate/2024.6-ruff-0.x Change-Id: I8f8e865435fde1fc736fe2528261a604acb46215 Priv-Id: f7e1d99008e3617149c4b639a9a2bbc06212d064

@ntBre ntBre mentioned this pull request

May 13, 2026

ntBre added a commit that referenced this pull request

May 15, 2026

@ntBre

Summary

This PR fixes #24807 by making RemoveSoftLinesBuffer aware of BestFitting and always selecting the most-flat variant, as suggested in [Micha's comment], assuming I interpreted it correctly.

As I noted on the issue, I was hoping I could get away with making a local change to the lambda formatting, but this turned out to affect the two other uses of RemoveSoftLinesBuffer too.

The formatting of the new regression tests:

def foo():
    subprocess.check_call(f"rm -rf {' '.join(map(lambda object_name: os.path.join(dest_path, object_name), objects_to_remove))}", shell=True)

def bar():
    lambda x=" ".join(
        map(lambda object_name: os.path.join(dest_path, object_name), objects_to_remove)
    ): ...

value = f"prefix {
    ' '.join(map(lambda object_name: os.path.join(dest_path, object_name), objects_to_remove))
} suffix"

now (nearly) matches the output before #21385:

❯ git diff <(uvx ruff@0.14.10 format - < fmt.py) <(./target/debug/ruff format - < fmt.py)
 def bar():
-    lambda x=" ".join(
-        map(lambda object_name: os.path.join(dest_path, object_name), objects_to_remove)
-    ): ...
+    lambda x=" ".join(map(lambda object_name: os.path.join(dest_path, object_name), objects_to_remove)): (
+        ...
+    )

 value = f"prefix {

with the only difference being that the body of this second lambda still wraps in the new formatting.

Test Plan

New tests based on the reported issue and possibly the ecosystem check on this PR

[Micha's comment]: #24807 (comment)

thejchap pushed a commit to thejchap/ruff that referenced this pull request

May 23, 2026

@ntBre @thejchap

…5144)

Summary

This PR fixes astral-sh#24807 by making RemoveSoftLinesBuffer aware of BestFitting and always selecting the most-flat variant, as suggested in [Micha's comment], assuming I interpreted it correctly.

As I noted on the issue, I was hoping I could get away with making a local change to the lambda formatting, but this turned out to affect the two other uses of RemoveSoftLinesBuffer too.

The formatting of the new regression tests:

def foo():
    subprocess.check_call(f"rm -rf {' '.join(map(lambda object_name: os.path.join(dest_path, object_name), objects_to_remove))}", shell=True)

def bar():
    lambda x=" ".join(
        map(lambda object_name: os.path.join(dest_path, object_name), objects_to_remove)
    ): ...

value = f"prefix {
    ' '.join(map(lambda object_name: os.path.join(dest_path, object_name), objects_to_remove))
} suffix"

now (nearly) matches the output before astral-sh#21385:

❯ git diff <(uvx ruff@0.14.10 format - < fmt.py) <(./target/debug/ruff format - < fmt.py)
 def bar():
-    lambda x=" ".join(
-        map(lambda object_name: os.path.join(dest_path, object_name), objects_to_remove)
-    ): ...
+    lambda x=" ".join(map(lambda object_name: os.path.join(dest_path, object_name), objects_to_remove)): (
+        ...
+    )

 value = f"prefix {

with the only difference being that the body of this second lambda still wraps in the new formatting.

Test Plan

New tests based on the reported issue and possibly the ecosystem check on this PR

[Micha's comment]: astral-sh#24807 (comment)

anishgirianish pushed a commit to anishgirianish/ruff that referenced this pull request

May 28, 2026

@ntBre @anishgirianish

…5144)

Summary

This PR fixes astral-sh#24807 by making RemoveSoftLinesBuffer aware of BestFitting and always selecting the most-flat variant, as suggested in [Micha's comment], assuming I interpreted it correctly.

As I noted on the issue, I was hoping I could get away with making a local change to the lambda formatting, but this turned out to affect the two other uses of RemoveSoftLinesBuffer too.

The formatting of the new regression tests:

def foo():
    subprocess.check_call(f"rm -rf {' '.join(map(lambda object_name: os.path.join(dest_path, object_name), objects_to_remove))}", shell=True)

def bar():
    lambda x=" ".join(
        map(lambda object_name: os.path.join(dest_path, object_name), objects_to_remove)
    ): ...

value = f"prefix {
    ' '.join(map(lambda object_name: os.path.join(dest_path, object_name), objects_to_remove))
} suffix"

now (nearly) matches the output before astral-sh#21385:

❯ git diff <(uvx ruff@0.14.10 format - < fmt.py) <(./target/debug/ruff format - < fmt.py)
 def bar():
-    lambda x=" ".join(
-        map(lambda object_name: os.path.join(dest_path, object_name), objects_to_remove)
-    ): ...
+    lambda x=" ".join(map(lambda object_name: os.path.join(dest_path, object_name), objects_to_remove)): (
+        ...
+    )

 value = f"prefix {

with the only difference being that the body of this second lambda still wraps in the new formatting.

Test Plan

New tests based on the reported issue and possibly the ecosystem check on this PR

[Micha's comment]: astral-sh#24807 (comment)

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters

[ Show hidden characters]({{ revealButtonHref }})