github dosisod/refurb v1.10.0
Version 1.10.0

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

Add ability to ignore checks on a per-file/folder basis

You can now ignore errors for a given path! Just add the following to your pyproject.toml:

[[tool.refurb.amend]]
path = "your/path/here"  # <-- can be a file or folder
ignore = ["FURB123"]

Read the docs for more info on how to use this new feature!

Add use-pathlib-mkdir check (FURB150)

Use the mkdir function from the pathlib library instead of using the mkdir and makedirs functions from the os library.

The following code:

import os

os.mkdir("new_folder")

Can be written like:

from pathlib import Path

Path("new_folder").mkdir()

Add use-pathlib-touch check (FURB151)

Don't use open(x, "w").close() if you just want to create an empty file, use the less confusing Path.touch() method instead.

Note that this check is disabled by default (expand this for a full explanation).
This check is disabled by default because `touch()` will throw a `FileExistsError` if the file already exists, and (at least on Linux) it sets different file permissions, meaning it is not a drop-in replacement. If you don't care about the file permissions or know that the file doesn't exist beforehand this check may be for you.

For example, this code:

open("file.txt", "w").close()

Can be written like this:

from pathlib import Path

Path("file.txt").touch()

Add use-math-constant check (FURB152)

Don't hardcode math constants like pi, tau, or e, use the math.pi, math.tau, or math.e constants respectively instead.

For example, this code:

def area(r: float) -> float:
    return 3.1415 * r * r

Should be written like this:

import math

def area(r: float) -> float:
    return math.pi * r * r

Add simplify-path-constructor check (FURB153)

The Path() constructor defaults to the current directory, so don't pass the current directory (".") explicitly.

This:

file = Path(".")

Can be written like this:

file = Path()

Add names to checks

All checks now contain a name field which makes them easier to refer to. Although the name isn't actually used for anything, you will eventually be able to use the name field as a replacement for FURBxxx on the CLI, in config files, and in noqa comments. In addition, the name (along with the categories) will be printed at the top of the "explainer" for the check when using --explain.

What's Changed

Full Changelog: v1.9.1...v1.10.0

Don't miss a new refurb release

NewReleases is sending notifications on new releases.