github dosisod/refurb v1.11.0

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

This version includes a couple of new checks, including a new check from first-time contributor @doomedraven!

Add simplify-global-and-nonlocal check (FURB154)

The global and nonlocal statements can take multiple variables, meaning you don't need to have a separate line for each variable:

def f():
    nonlocal x
    nonlocal y

    ...

The above code can be written like this instead:

def f():
    nonlocal x, y

    ...

Add use-pathlib-stat check (FURB155)

This check suggests that you use the pathlib module for doing stat() file operations, such as getting the file size, date modified, etc.

For example, the following code:

if os.path.getsize("file.txt"):
    pass

Can be written like this:

if Path("file.txt").stat().st_size:
    pass

Add use-string-charsets check (FURB156)

The string library offers some common charsets such as digits, upper/lower case alpha characters, and more. This improves readability, and cuts down on line length as well.

For example:

digits = "0123456789"

if c in digits:
    pass

if c in "0123456789abcdefABCDEF":
    pass

The above code can be written like this using the string module:

if c in string.digits:
    pass

if c in string.hexdigits:
    pass

Add simplify-decimal-ctor check (FURB157)

The Decimal() constructor can take many different types such as str, int, and float. Often times you can simplify the construction of Decimal objects, especially when using plain literals such as "0".

if x == Decimal("0"):
    pass

if y == Decimal(float("Infinity")):
    pass

Good:

if x == Decimal(0):
    pass

if y == Decimal("Infinity"):
    pass

What's Changed

  • Add more info to the explaination output by @dosisod in #185
  • Add "simplify-global-and-nonlocal" check by @dosisod in #186
  • Fix FURB123 (no-redundant-cast) suggesting to use .copy() for literals by @dosisod in #188
  • replace os.path.getsize with Path("file.txt").stat().st_size by @doomedraven in #189
  • Add normalize_os_path helper function by @dosisod in #193
  • Add use-string-charsets check by @dosisod in #194
  • Add simplify-decimal-ctor check by @dosisod in #195
  • Bump packages, bump version to 1.11.0 by @dosisod in #196

New Contributors

Full Changelog: v1.10.0...v1.11.0

Don't miss a new refurb release

NewReleases is sending notifications on new releases.