This check includes a few bug fixes, as well as many new checks!
The --python-version
setting defaults to currently installed version now
Previously Refurb would be completely unaware of what version of Python you where checking unless you set the --python-version 3.x
flag. Now, unless you override it with that flag, Refurb will default to whatever the currently installed version of Python on your machine is.
Add simplify-strip
check (FURB159)
In some situations the .lstrip()
, .rstrip()
and .strip()
string methods can be written more succinctly: strip()
is the same thing as calling both lstrip()
and rstrip()
together, and all the strip functions take an iterable argument of the characters to strip, meaning you don't need to call a strip function multiple times with different arguments, you can just concatenate them and call it once.
Bad:
name = input().lstrip().rstrip()
num = " -123".lstrip(" ").lstrip("-")
Good:
name = input().strip()
num = " -123".lstrip(" -")
Add no-redundant-assignment
check (FURB160)
Sometimes when you are debugging (or copy-pasting code) you will end up with a variable that is assigning itself to itself. These lines can be removed.
Bad:
name = input("What is your name? ")
name = name
Good:
name = input("What is your name? ")
Add use-bit-count
check (FURB161)
Python 3.10 adds a very helpful bit_count()
function for integers which counts the number of set bits. This new function is more descriptive and faster compared to converting/counting characters in a string.
Bad:
x = bin(0b1010).count("1")
assert x == 2
Good:
x = 0b1010.bit_count()
assert x == 2
Add simplify-fromisoformat
check (FURB162)
Python 3.11 adds support for parsing UTC timestamps that end with Z
, thus removing the need to strip and append the +00:00
timezone.
Bad:
date = "2023-02-21T02:23:15Z"
start_date = datetime.fromisoformat(date.replace("Z", "+00:00"))
Good:
date = "2023-02-21T02:23:15Z"
start_date = datetime.fromisoformat(date)
What's Changed
- Add
simplify-strip
check by @dosisod in #202 - Add more flake8 plugins by @dosisod in #204
- Add
no-redundant-assignment
check by @dosisod in #205 - Add
use-bit-count
check by @dosisod in #208 - Emit error for empty string in
Path()
constructor by @dosisod in #209 - Add
simplify-fromisoformat
check by @dosisod in #210 - Set
python_version
to currently installed Python version by @dosisod in #211 - Replace
flake8
withruff
, bump version by @dosisod in #212
Full Changelog: v1.12.0...v1.13.0