-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Permalink
Choose a base ref
{{ refName }}
default
Choose a head ref
{{ refName }}
default
Checking mergeability…
Don’t worry, you can still create the pull request.
Comparing changes
Choose two branches to see what’s changed or to start a new pull request.
If you need to, you can also or
learn more about diff comparisons.
Open a pull request
Create a new pull request by comparing changes across two branches. If you need to, you can also .
Learn more about diff comparisons here.
base repository: astral-sh/ruff
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: main
Could not load branches
Nothing to show
Loading
Could not load tags
Nothing to show
{{ refName }}
default
Loading
...
head repository: astral-sh/ruff
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: brent/unary-comment2
Could not load branches
Nothing to show
Loading
Could not load tags
Nothing to show
{{ refName }}
default
Loading
- 8 commits
- 3 files changed
- 2 contributors
Commits on Nov 12, 2025
-
Fix panic when formatting comments in unary expressions
Summary -- This is a second attempt at fixing #19226 based on the feedback in #20494 (comment). We currently mark the comment in an expression like this: ```py if '' and (not # 0): pass ``` as a leading comment on `not`, eventually causing a panic in `Operand::has_unparenthesized_leading_comments` because the end of the comment is greater than the start of the expression. https://github.com/astral-sh/ruff/blob/a1d9cb5830eca9b63e7fb529504fc536e99bca23/crates/ruff_python_formatter/src/expression/binary_like.rs#L843 This PR fixes the issue by instead making such a comment a dangling comment on the unary expression. In the third commit, I instead tried making the comment a leading comment on the operand, which also looks pretty reasonable to me. Making it a dangling comment seems more in line with the docs on `handle_unary_op_comments`, though. I also tried deleting the leading comment logic in favor of the new dangling logic in the fifth commit before reverting in the sixth. This looks okay to me too, but the current state of the PR seems like the least invasive fix. Test Plan -- A new, minimized test case based on the issue. I also checked that the original snippet from the report works now. Co-authored-by: Takayuki Maeda <[email protected]>
Configuration menu - View commit details
-
Copy full SHA for 923b4dd - Browse repository at this point
Copy the full SHA 923b4ddView commit details -
Configuration menu - View commit details
-
Copy full SHA for 6eebc35 - Browse repository at this point
Copy the full SHA 6eebc35View commit details -
Configuration menu - View commit details
-
Copy full SHA for a303d1a - Browse repository at this point
Copy the full SHA a303d1aView commit details -
Configuration menu - View commit details
-
Copy full SHA for ecccfd2 - Browse repository at this point
Copy the full SHA ecccfd2View commit details -
Configuration menu - View commit details
-
Copy full SHA for 1cf5eff - Browse repository at this point
Copy the full SHA 1cf5effView commit details -
This reverts commit 4c8540ede798f544a895225b541f46552649fd7b.
Configuration menu - View commit details
-
Copy full SHA for f49fda3 - Browse repository at this point
Copy the full SHA f49fda3View commit details
Commits on Nov 13, 2025
-
Configuration menu - View commit details
-
Copy full SHA for 9bee558 - Browse repository at this point
Copy the full SHA 9bee558View commit details -
Configuration menu - View commit details
-
Copy full SHA for e0b0b54 - Browse repository at this point
Copy the full SHA e0b0b54View commit details
Loading
This comparison is taking too long to generate.
Unfortunately it looks like we can’t render this comparison for you right now. It might be too big, or there might be something weird with your repository.
You can try running this command locally to see the comparison on your machine:
git diff main...brent/unary-comment2