mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-28 12:55:05 +00:00
Don't reorder parameters in function calls (#7268)
## Summary In `f(*args, a=b, *args2, **kwargs)` the args (`*args`, `*args2`) and keywords (`a=b`, `**kwargs`) are interleaved, which we previously didn't handle. Fixes #6498 **main** | project | similarity index | total files | changed files | |--------------|------------------:|------------------:|------------------:| | cpython | 0.76083 | 1789 | 1632 | | **django** | 0.99966 | 2760 | 58 | | transformers | 0.99930 | 2587 | 447 | | twine | 1.00000 | 33 | 0 | | typeshed | 0.99983 | 3496 | 18 | | warehouse | 0.99825 | 648 | 22 | | zulip | 0.99950 | 1437 | 27 | **PR** | project | similarity index | total files | changed files | |--------------|------------------:|------------------:|------------------:| | cpython | 0.76083 | 1789 | 1632 | | **django** | 0.99967 | 2760 | 53 | | transformers | 0.99930 | 2587 | 447 | | twine | 1.00000 | 33 | 0 | | typeshed | 0.99983 | 3496 | 18 | | warehouse | 0.99825 | 648 | 22 | | zulip | 0.99950 | 1437 | 27 | ## Test Plan New fixtures
This commit is contained in:
parent
56440ad835
commit
f4c7bff36b
6 changed files with 203 additions and 129 deletions
|
@ -38,7 +38,7 @@ pub(super) fn place_comment<'a>(
|
|||
/// ):
|
||||
/// ...
|
||||
/// ```
|
||||
/// The parentheses enclose `True`, but the range of `True`doesn't include the `# comment`.
|
||||
/// The parentheses enclose `True`, but the range of `True` doesn't include the `# comment`.
|
||||
///
|
||||
/// Default handling can get parenthesized comments wrong in a number of ways. For example, the
|
||||
/// comment here is marked (by default) as a trailing comment of `x`, when it should be a leading
|
||||
|
@ -120,10 +120,8 @@ fn handle_parenthesized_comment<'a>(
|
|||
// For now, we _can_ assert, but to do so, we stop lexing when we hit a token that precedes an
|
||||
// identifier.
|
||||
if comment.line_position().is_end_of_line() {
|
||||
let tokenizer = SimpleTokenizer::new(
|
||||
locator.contents(),
|
||||
TextRange::new(preceding.end(), comment.start()),
|
||||
);
|
||||
let range = TextRange::new(preceding.end(), comment.start());
|
||||
let tokenizer = SimpleTokenizer::new(locator.contents(), range);
|
||||
if tokenizer
|
||||
.skip_trivia()
|
||||
.take_while(|token| {
|
||||
|
@ -136,7 +134,7 @@ fn handle_parenthesized_comment<'a>(
|
|||
debug_assert!(
|
||||
!matches!(token.kind, SimpleTokenKind::Bogus),
|
||||
"Unexpected token between nodes: `{:?}`",
|
||||
locator.slice(TextRange::new(preceding.end(), comment.start()),)
|
||||
locator.slice(range)
|
||||
);
|
||||
|
||||
token.kind() == SimpleTokenKind::LParen
|
||||
|
@ -145,10 +143,8 @@ fn handle_parenthesized_comment<'a>(
|
|||
return CommentPlacement::leading(following, comment);
|
||||
}
|
||||
} else {
|
||||
let tokenizer = SimpleTokenizer::new(
|
||||
locator.contents(),
|
||||
TextRange::new(comment.end(), following.start()),
|
||||
);
|
||||
let range = TextRange::new(comment.end(), following.start());
|
||||
let tokenizer = SimpleTokenizer::new(locator.contents(), range);
|
||||
if tokenizer
|
||||
.skip_trivia()
|
||||
.take_while(|token| {
|
||||
|
@ -161,7 +157,7 @@ fn handle_parenthesized_comment<'a>(
|
|||
debug_assert!(
|
||||
!matches!(token.kind, SimpleTokenKind::Bogus),
|
||||
"Unexpected token between nodes: `{:?}`",
|
||||
locator.slice(TextRange::new(comment.end(), following.start()))
|
||||
locator.slice(range)
|
||||
);
|
||||
token.kind() == SimpleTokenKind::RParen
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue