Skip to content

Version 1.13.0

Compare
Choose a tag to compare
@dosisod dosisod released this 23 Feb 08:08
· 184 commits to master since this release
4e87722

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

Full Changelog: v1.12.0...v1.13.0