Skip to content

Commit

Permalink
[ruff] Detect more strict-integer expressions (RUF046)
Browse files Browse the repository at this point in the history
  • Loading branch information
InSyncWithFoo committed Dec 11, 2024
1 parent c361cf6 commit e4185d2
Show file tree
Hide file tree
Showing 3 changed files with 813 additions and 219 deletions.
82 changes: 82 additions & 0 deletions crates/ruff_linter/resources/test/fixtures/ruff/RUF046.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,26 @@
int(round(1.))
int(round(1., None))

int(1)
int(v := 1)
int(~1)
int(-1)
int(+1)

int(1 + 1)
int(1 - 1)
int(1 * 1)
int(1 % 1)
int(1 ** 1)
int(1 << 1)
int(1 >> 1)
int(1 | 1)
int(1 ^ 1)
int(1 & 1)
int(1 // 1)

int(1 if ... else 2)


### Unsafe

Expand Down Expand Up @@ -68,3 +88,65 @@

int(round(0, 0), base)
int(round(0, 0, extra=keyword))

int(1 and 0)
int(0 or -1)

int(foo if ... else 4)

int(3.14)
int(2.8j)

async def f():
int(await f())

int(foo.bar)
int(bar([1][False]))

int(1 == 1)
int(1 != 1)
int(1 < 1)
int(1 <= 1)
int(1 > 1)
int(1 >= 1)
int(1 in 1)
int(1 not in 1)
int(1 is 1)
int(2 is not 3)
int(foo in 1)
int(foo not in 1)
int(foo is 1)
int(foo is not 1)

int(1 == 2 == 3)
int(foo == 1)
int(foo != 1)
int(foo < 1)
int(foo <= 1)
int(foo > 1)
int(foo >= 1)

int(v := {}[{}['']])

int(foo + 1)
int(foo - 1)
int(foo * 1)
int(foo @ 1)
int(foo / 1)
int(foo % 1)
int(foo ** 1)
int(foo << 1)
int(foo >> 1)
int(foo | 1)
int(foo ^ 1)
int(foo & 1)
int(foo // 1)

int(v := 3.7)

int(not 109)

int(1 / 1)
int(1 @ 1)

int(1. if ... else .2)
Loading

0 comments on commit e4185d2

Please sign in to comment.