github dosisod/refurb v1.14.0
Version 1.14.0

latest releases: v2.0.0, v1.28.0, v1.27.0...
18 months ago

This PR includes a few bug fixes, a few new features, and 4 new checks!

Bug Fixes

  • Error codes can be comma separated in noqa comments now
  • Unused fields or fields with the wrong type will throw an error now

New Features

  • Add ability to output GitHub Annotations using --format github
  • Add ability to sort error output by error code via --sort error

Add simplify-math-log check (FURB163)

Use the shorthand log2 and log10 functions instead of passing 2 or 10 as the second argument to the log function. If math.e is used as the second argument, just use math.log(x) instead, since e is the default.

Bad:

power = math.log(x, 10)

Good:

power = math.log10(x)

Add no-from-float check (FURB164)

When constructing a Fraction or Decimal using a float, don't use the from_float() or from_decimal() class methods: Just use the more consice Fraction() and Decimal() class constructors instead.

Bad:

ratio = Fraction.from_float(1.2)
score = Decimal.from_float(98.0)

Good:

ratio = Fraction(1.2)
score = Decimal(98.0)

Add no-temp-class-object check (FURB165)

You don't need to construct a class object to call a static method or a class method, just invoke the method on the class directly:

Bad:

cwd = Path().cwd()

Good:

cwd = Path.cwd()

Add use-int-base-zero check (FURB166)

When converting a string starting with 0b, 0o, or 0x to an int, you don't need to slice the string and set the base yourself: just call int() with a base of zero. Doing this will autodeduce the correct base to use based on the string prefix.

Bad:

num = "0xABC"

if num.startswith("0b"):
    i = int(num[2:], 2)
elif num.startswith("0o"):
    i = int(num[2:], 8)
elif num.startswith("0x"):
    i = int(num[2:], 16)

print(i)

Good:

num = "0xABC"

i = int(num, 0)

print(i)

This check is disabled by default because there is no way for Refurb to detect whether the prefixes that are being stripped are valid Python int prefixes (like 0x) or some other prefix which would fail if parsed using this method.

What's Changed

Full Changelog: v1.13.0...v1.14.0

Don't miss a new refurb release

NewReleases is sending notifications on new releases.