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).
Python 3.9 and newer is supported.
Install from PyPI. For example,
pip install flake8-ruffThen follow the instructions on the Flake8 documentation to enable the plugin.
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).
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 Nonewith
result = foo()
assert result is not NoneDerived from assignment-in-assert (RUF018).
Checks for typing.Never and typing.NoReturn in union types, which is
redundant.
For example, replace
typing.Never | int | Nonewith
int | NoneDerived from never-union (RUF020).
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).