Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support floating-point base in FURB163 #9100

Merged
merged 2 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions crates/ruff_linter/resources/test/fixtures/refurb/FURB163.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
special_log(1, 10)
special_log(1, math.e)
special_log(1, special_e)
math.log(1, 2.0)
math.log(1, 10.0)

# Ok.
math.log2(1)
Expand Down Expand Up @@ -45,3 +47,6 @@ def log(*args):
log(1, 2)
log(1, 10)
log(1, math.e)

math.log(1, 2.0001)
math.log(1, 10.0001)
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ fn is_number_literal(expr: &Expr, value: i8) -> bool {
if let Expr::NumberLiteral(number_literal) = expr {
if let Number::Int(number) = &number_literal.value {
return number.as_i8().is_some_and(|number| number == value);
} else if let Number::Float(number) = number_literal.value {
return number == f64::from(value);
}
}
false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ FURB163.py:16:1: FURB163 [*] Prefer `math.log10(1)` over `math.log` with a redun
16 |+math.log10(1)
17 17 | special_log(1, math.e)
18 18 | special_log(1, special_e)
19 19 |
19 19 | math.log(1, 2.0)

FURB163.py:17:1: FURB163 [*] Prefer `math.log(1)` over `math.log` with a redundant base
|
Expand All @@ -196,6 +196,7 @@ FURB163.py:17:1: FURB163 [*] Prefer `math.log(1)` over `math.log` with a redunda
17 | special_log(1, math.e)
| ^^^^^^^^^^^^^^^^^^^^^^ FURB163
18 | special_log(1, special_e)
19 | math.log(1, 2.0)
|
= help: Replace with `math.log(1)`

Expand All @@ -206,17 +207,17 @@ FURB163.py:17:1: FURB163 [*] Prefer `math.log(1)` over `math.log` with a redunda
17 |-special_log(1, math.e)
17 |+math.log(1)
18 18 | special_log(1, special_e)
19 19 |
20 20 | # Ok.
19 19 | math.log(1, 2.0)
20 20 | math.log(1, 10.0)

FURB163.py:18:1: FURB163 [*] Prefer `math.log(1)` over `math.log` with a redundant base
|
16 | special_log(1, 10)
17 | special_log(1, math.e)
18 | special_log(1, special_e)
| ^^^^^^^^^^^^^^^^^^^^^^^^^ FURB163
19 |
20 | # Ok.
19 | math.log(1, 2.0)
20 | math.log(1, 10.0)
|
= help: Replace with `math.log(1)`

Expand All @@ -226,8 +227,49 @@ FURB163.py:18:1: FURB163 [*] Prefer `math.log(1)` over `math.log` with a redunda
17 17 | special_log(1, math.e)
18 |-special_log(1, special_e)
18 |+math.log(1)
19 19 |
20 20 | # Ok.
21 21 | math.log2(1)
19 19 | math.log(1, 2.0)
20 20 | math.log(1, 10.0)
21 21 |

FURB163.py:19:1: FURB163 [*] Prefer `math.log2(1)` over `math.log` with a redundant base
|
17 | special_log(1, math.e)
18 | special_log(1, special_e)
19 | math.log(1, 2.0)
| ^^^^^^^^^^^^^^^^ FURB163
20 | math.log(1, 10.0)
|
= help: Replace with `math.log2(1)`

ℹ Safe fix
16 16 | special_log(1, 10)
17 17 | special_log(1, math.e)
18 18 | special_log(1, special_e)
19 |-math.log(1, 2.0)
19 |+math.log2(1)
20 20 | math.log(1, 10.0)
21 21 |
22 22 | # Ok.

FURB163.py:20:1: FURB163 [*] Prefer `math.log10(1)` over `math.log` with a redundant base
|
18 | special_log(1, special_e)
19 | math.log(1, 2.0)
20 | math.log(1, 10.0)
| ^^^^^^^^^^^^^^^^^ FURB163
21 |
22 | # Ok.
|
= help: Replace with `math.log10(1)`

ℹ Safe fix
17 17 | special_log(1, math.e)
18 18 | special_log(1, special_e)
19 19 | math.log(1, 2.0)
20 |-math.log(1, 10.0)
20 |+math.log10(1)
21 21 |
22 22 | # Ok.
23 23 | math.log2(1)


Loading