Skip to content

Commit

Permalink
add binop early return
Browse files Browse the repository at this point in the history
  • Loading branch information
diceroll123 committed Oct 30, 2024
1 parent 87f586b commit 6bbcc0c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions crates/ruff_linter/resources/test/fixtures/pyupgrade/UP044.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ class D(Generic[Unpack [Shape]]):
pass

def f(*args: Unpack[tuple[int, ...]]): pass

def foo(*args: Unpack[int | str]) -> None: pass # not supported
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ pub(crate) fn use_pep646_unpack(checker: &mut Checker, expr: &ExprSubscript) {
return;
}

if slice.is_bin_op_expr() {
// fixing this would introduce a syntax error
return;
}

let mut diagnostic = Diagnostic::new(NonPEP646Unpack, *range);

let inner = checker.locator().slice(slice.as_ref());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ UP044.py:11:14: UP044 [*] Use `*` for unpacking
10 |
11 | def f(*args: Unpack[tuple[int, ...]]): pass
| ^^^^^^^^^^^^^^^^^^^^^^^ UP044
12 |
13 | def foo(*args: Unpack[int | str]) -> None: pass # not supported
|
= help: Convert to `*` for unpacking

Expand All @@ -56,3 +58,5 @@ UP044.py:11:14: UP044 [*] Use `*` for unpacking
10 10 |
11 |-def f(*args: Unpack[tuple[int, ...]]): pass
11 |+def f(*args: *tuple[int, ...]): pass
12 12 |
13 13 | def foo(*args: Unpack[int | str]) -> None: pass # not supported

0 comments on commit 6bbcc0c

Please # to comment.