Fix leading comment formatting for lambdas with multiple parameters#21879
Merged
Fix leading comment formatting for lambdas with multiple parameters#21879
Conversation
the new leading comment is causing the whole Parameters list to break. these
cases should instead format like:
```py
(
lambda
# comment
*x, **y: x
)
(
lambda
# comment 2
*x, **y: x
)
```
without line breaks in the parameter list
|
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as duplicate.
This comment was marked as duplicate.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
and fix some names the start check handles both the `are_parameters_parenthesized` check (because lambda parameters cannot be parenthesized and thus nothing can come between the start of the parameters and the first parameter) and the comparison with first.range() since the parameters start where the first parameter starts
I believe parameters itself would be None if there were no next parameter
MichaReiser
approved these changes
Dec 9, 2025
dcreager
added a commit
that referenced
this pull request
Dec 10, 2025
* origin/main: (33 commits) [ty] Simplify union lower bounds and intersection upper bounds in constraint sets (#21871) [ty] Collapse `never` paths in constraint set BDDs (#21880) Fix leading comment formatting for lambdas with multiple parameters (#21879) [ty] Type inference for `@asynccontextmanager` (#21876) Fix comment placement in lambda parameters (#21868) [`pylint`] Detect subclasses of builtin exceptions (`PLW0133`) (#21382) Fix stack overflow with recursive generic protocols (depth limit) (#21858) New diagnostics for unused range suppressions (#21783) [ty] Use default settings in completion tests [ty] Infer type variables within generic unions (#21862) [ty] Fix overload filtering to prefer more "precise" match (#21859) [ty] Stabilize auto-import [ty] Fix reveal-type E2E test (#21865) [ty] Use concise message for LSP clients not supporting related diagnostic information (#21850) Include more details in Tokens 'offset is inside token' panic message (#21860) apply range suppressions to filter diagnostics (#21623) [ty] followup: add-import action for `reveal_type` too (#21668) [ty] Enrich function argument auto-complete suggestions with annotated types [ty] Add autocomplete suggestions for function arguments [`flake8-bugbear`] Accept immutable slice default arguments (`B008`) (#21823) ...
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This is a follow-up to #21868. As soon as I started merging #21868 into #21385, I realized that I had missed a test case with
**kwargsafter the*argsparameter. Such a case is supposed to be formatted on one line like:which you can still see on the playground, but on
mainafter #21868, this was formatted as:( lambda # comment *x, **y: x )because the leading comment on the first parameter caused the whole group around the parameters to break.
Instead of making these comments leading comments on the first parameter, this PR makes them leading comments on the parameters list as a whole.
Test Plan
New tests, and I will also try merging this into #21385 before opening it for review this time.
(labeling
internalsince #21868 should not be released before some kind of fix)