A Flake8 plugin that implements miscellaneous checks from Ruff.
Project description
flake8-ruff
A Flake8 plugin that implements miscellaneous checks from Ruff.
Specifically, this plugin implements checks that are under the RUF
category
(the rules that do not have a direct equivalent in Flake8).
Requirements
Python 3.9 to 3.12 is supported.
Installation
Install from PyPI. For example,
pip install flake8-ruff
Then follow the instructions on the Flake8 documentation to enable the plugin.
Checks
RUF010 Use explicit conversion flag
Checks for str()
, repr()
, and ascii()
as explicit conversions within
f-strings.
For example, replace
f"{ascii(foo)}, {repr(bar)}, {str(baz)}"
with
f"{foo!a}, {bar!r}, {baz!s}"
or, often (such as where __str__
and __format__
are equivalent),
f"{foo!a}, {bar!r}, {baz}"
Derived from explicit-f-string-type-conversion (RUF010).
RUF018 Avoid assignment expressions in assert
statements
Checks for named assignment expressions in assert
statements. When Python is
run with the -O
option, the assert
statement is ignored, and the assignment
expression is not executed. This can lead to unexpected behavior.
For example, replace
assert (result := foo()) is not None
with
result = foo()
assert result is not None
Derived from assignment-in-assert (RUF018).
RUF020 typing.Never | T
is equivalent to T
Checks for typing.Never
and typing.NoReturn
in union types, which is
redundant.
For example, replace
typing.Never | int | None
with
int | None
Derived from never-union (RUF020).
RUF025 Unnecessary dict comprehension for iterable; use dict.fromkeys
instead
Checks for dict comprehensions that create a dictionary from an iterable with a
constant value. Instead, use dict.fromkeys
, which is more efficient.
For example, replace
{key: 0 for key in keys}
with
dict.fromkeys(keys, 0)
and
{key: None for key in keys}
with
dict.fromkeys(keys)
Derived from unnecessary-dict-comprehension-for-iterable (RUF025).
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file flake8_ruff-0.3.0.tar.gz
.
File metadata
- Download URL: flake8_ruff-0.3.0.tar.gz
- Upload date:
- Size: 3.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.9.18 Linux/6.2.0-1019-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e45ac429d68f683228c0851a9363c191e8f67c2ea3af33f798c465f55aee0940 |
|
MD5 | 7550bf9f44010763e89d419a9e41f13c |
|
BLAKE2b-256 | cd9896f94f55cd067c51cfdf762f14ba547eff4fd2bc9688f5443ca16873ab8a |
File details
Details for the file flake8_ruff-0.3.0-py3-none-any.whl
.
File metadata
- Download URL: flake8_ruff-0.3.0-py3-none-any.whl
- Upload date:
- Size: 3.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.9.18 Linux/6.2.0-1019-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 00c3967c84ceac7702a2917743fe7abc1bd302013b2e45518d867d6482d0034b |
|
MD5 | 6c85b5f8c032e42fa0cf756f16458a7e |
|
BLAKE2b-256 | 9a8337392193b3224b2003f3dd93226241e7ac2a08e4d0d3190d765a00c6a78c |