Skip to main content

A Flake8 plugin that implements miscellaneous checks from Ruff.

Project description

flake8-ruff

image

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 and newer 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

flake8_ruff-0.3.1.tar.gz (26.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

flake8_ruff-0.3.1-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

Details for the file flake8_ruff-0.3.1.tar.gz.

File metadata

  • Download URL: flake8_ruff-0.3.1.tar.gz
  • Upload date:
  • Size: 26.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for flake8_ruff-0.3.1.tar.gz
Algorithm Hash digest
SHA256 afa65ef8c84760593db76d9c5cec7d7a588b499792461f048924280ac89bb7b4
MD5 654099b00a089602a565a2a58d6ea608
BLAKE2b-256 e270892dc878ba2245aa62b34a3bb89405eeb6062dbe2e8b8af9e9f982d35d02

See more details on using hashes here.

Provenance

The following attestation bundles were made for flake8_ruff-0.3.1.tar.gz:

Publisher: main.yaml on tjkuson/flake8-ruff

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file flake8_ruff-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: flake8_ruff-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 4.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for flake8_ruff-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d0d71e066df562b7307cb2cb3a646a7b55018fdeebc5457167f3f1b652d8d2fe
MD5 28143e5da1528b2a6ff0eeb851a77a73
BLAKE2b-256 5597c6f1961927d9d4df147d8a84b5ad2cab8ae71ca3c424b326abc09049b172

See more details on using hashes here.

Provenance

The following attestation bundles were made for flake8_ruff-0.3.1-py3-none-any.whl:

Publisher: main.yaml on tjkuson/flake8-ruff

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page