This release adds 3 new checks and some general bug fixes.
Add use-suffix
check (FURB172)
Note: This check is disabled by default.
When checking the file extension for a pathlib object don't call endswith()
on the name
field, directly check against suffix
instead.
Bad:
from pathlib import Path
def is_markdown_file(file: Path) -> bool:
return file.name.endswith(".md")
Good:
from pathlib import Path
def is_markdown_file(file: Path) -> bool:
return file.suffix == ".md"
Add use-dict-union
check (FURB173)
Dicts can be created/combined in many ways, one of which is the **
operator (inside the dict), and another is the |
operator (used outside the dict). While they both have valid uses, the |
operator allows for more flexibility, including using |=
to update an existing dict.
See PEP 584 for more info.
Bad:
def add_defaults(settings: dict[str, str]) -> dict[str, str]:
return {"color": "1", **settings}
Good:
def add_defaults(settings: dict[str, str]) -> dict[str, str]:
return {"color": "1"} | settings
Add simplify-token-function
check (FURB174)
Depending on how you are using the secrets
module there might be a more expressive ways of writing what it is you're trying to write.
Bad:
random_hex = token_bytes().hex()
random_url = token_urlsafe()[:16]
Good:
random_hex = token_hex()
random_url = token_urlsafe(16)
Bugs
- Fix
tuple
related issue in Mypy 1.4.0 where certain checks would be ignored - Ensure config file exists and is not a directory
- Disallow empty strings as arguments