You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
UP018/C408 detects some, but not all of the same errors as Refurb:
# detected by Ruff and Refurbl=list()
d=dict()
t=tuple()
# only detected by Refurbi=int()
f=float()
c=complex()
b=bool()
# missleading error message in Ruff, see belowby=bytes()
s=str()
Running in Ruff:
$ ruff x.py
x.py:1:1: E741 Ambiguous variable name: `l`
x.py:1:5: C408 [*] Unnecessary `list` call (rewrite as a literal)
x.py:2:5: C408 [*] Unnecessary `dict` call (rewrite as a literal)
x.py:3:5: C408 [*] Unnecessary `tuple` call (rewrite as a literal)
x.py:10:6: UP018 [*] Unnecessary call to `bytes`
x.py:11:5: UP018 [*] Unnecessary call to `str`
Running in Refurb:
$ refurb x.py
x.py:1:5 [FURB112]: Replace `list()` with `[]`
x.py:2:5 [FURB112]: Replace `dict()` with `{}`
x.py:3:5 [FURB112]: Replace `tuple()` with `()`
x.py:5:5 [FURB112]: Replace `int()` with `0`
x.py:6:5 [FURB112]: Replace `float()` with `0.0`
x.py:7:5 [FURB112]: Replace `complex()` with `0j`
x.py:8:5 [FURB112]: Replace `bool()` with `False`
x.py:10:6 [FURB112]: Replace `bytes()` with `b""`
x.py:11:5 [FURB112]: Replace `str()` with `""`
The "Unnecessary call to bytes/str" message is also misleading because there are no arguments to str()/bytes().
Very few projects according to grep.app are using the int(), str(), etc. form, but still worth adding IMO.
The text was updated successfully, but these errors were encountered:
## Summary
This pull request add supports for `int`, `float` and `bool` types in
`UP018`
rule to convert empty call to the default value of the type or remove
the call
if a value of the same type is provided as an argument.
## Test Plan
Added tests for `int`, `float` and `bool` types.
Partially resolves#5988
See #1348 (comment).
UP018
/C408
detects some, but not all of the same errors as Refurb:Running in Ruff:
Running in Refurb:
The "Unnecessary call to
bytes
/str
" message is also misleading because there are no arguments tostr()
/bytes()
.Very few projects according to grep.app are using the
int()
,str()
, etc. form, but still worth adding IMO.The text was updated successfully, but these errors were encountered: