Rules

Rattle’s built-in rules are grouped by collection. Enable a collection by adding its name to enable, or enable a single rule by its kebab-case name.

Blank Lines

Whitespace and statement-separation rules.

Enable with:

enable = ["blank-lines"]

Rule

Message

Python

Autofix

blank-line-after-control-block

Add a blank line after this multiline control-flow block.

Any

Yes

blank-line-after-terminal-control-block

Add a blank line after this early-exit control-flow block.

Any

Yes

blank-line-before-branch

Add a blank line before this branch statement in a larger code block.

Any

Yes

blank-line-before-unrelated-block

Add a blank line before this block; the preceding statements do not prepare values used by it.

Any

Yes

no-suite-leading-trailing-blank-lines

Remove blank lines at the beginning or end of a code block.

Any

Yes

Exports

Rules for explicit module export surfaces.

Enable with:

enable = ["exports"]

Rule

Message

Python

Autofix

module-all-at-bottom

Define module __all__ at the bottom of the file.

Any

Yes

no-underscore-all-exports

Do not export underscore-prefixed symbols in __all__. Either remove them from __all__ or rename them to be public.

Any

No

Policy

Configurable policy rules for architecture and naming boundaries.

Enable with:

enable = ["policy"]

Rule

Message

Python

Autofix

forbidden-call

Do not call forbidden callable ‘{symbol}’.

Any

No

forbidden-import

Do not import across forbidden boundary ‘{boundary}’.

Any

No

forbidden-name

Do not use forbidden {kind} name ‘{name}’.

Any

No

line-count-limit

{target} has {actual_lines} lines, exceeding the configured limit of {max_lines}.

Any

No

no-relative-imports

Use absolute imports instead of relative imports.

Any

No

no-underscore-import-aliases

Import aliases must not start with an underscore.

Any

No

no-unsafe-tempfile-factories

Use tempfile context managers instead of mkstemp or mkdtemp.

Any

No

Style

Rules for code style and structure.

Enable with:

enable = ["style"]

Rule

Message

Python

Autofix

no-annotated-self

Do not annotate self in instance methods.

Any

Yes

no-exception-message-variables

Inline exception message strings instead of assigning throwaway variables.

Any

Yes

no-str-exception-translation

Use a fixed message when translating an exception, and preserve the cause with raise ... from exc.

Any

No

no-underscore-class

Class names must not start with an underscore prefix.

Any

No

public-method-order

Define public methods before underscore-prefixed helper methods.

Any

No

Typing

Rules for type annotations and modern typing syntax.

Enable with:

enable = ["typing"]

Rule

Message

Python

Autofix

no-bare-object-annotations

Replace this bare object annotation with a type that describes the value.

Any

No

Fixit

Core lint rules inherited from Fixit.

Enable with:

enable = ["fixit"]

Rule

Message

Python

Autofix

explicit-frozen-dataclass

Dataclass mutability must be explicit. Add frozen=True for immutable value objects or frozen=False when instances are intentionally mutable.

Any

No

no-named-tuple

NamedTuple can often be replaced with @dataclass, but dataclasses are not tuple-compatible; check callers before converting.

Any

No

no-static-if-condition

This if condition appears constant; verify the logic and remove any temporary debug clause.

Any

No

sorted-attributes

Class assignments under @sorted-attributes are not sorted; sorting them can change right-hand-side side-effect order.

Any

Yes

use-callable-ellipsis

Use Callable[…, T] instead of Callable[[…], T].

Any

Yes

use-rattle-ignore-comment

Use rattle: ignore[rule-name]; Rattle does not support noqa.

Any

No

use-types-from-typing

Python 3.8 does not support {builtin_type}[...] annotations; use typing.{correct_type} instead.

< 3.9

Yes

Fixit Extra

Additional Fixit-derived rules that can be enabled separately.

Enable with:

enable = ["fixit-extra"]

Rule

Message

Python

Autofix

collapse-isinstance-checks

Multiple isinstance calls with the same target but different types can be collapsed into a single call with a tuple of types.

Any

No

deprecated-unittest-asserts

{deprecated} is deprecated; use {replacement} instead.

Any

Yes

no-inherit-from-object

Remove the redundant object base class.

Any

Yes

no-or-in-except

Use except (ValueError, TypeError):; except ValueError or TypeError: catches only ValueError.

Any

No

no-redundant-arguments-super

Call super() without arguments.

Any

No

no-redundant-f-string

Remove the f prefix; this f-string has no replacement fields.

Any

Yes

no-redundant-lambda

The lambda that wraps {function} is redundant and can be replaced by the callable.

Any

No

no-redundant-list-comprehension

Unnecessary list comprehension inside {func}(). Use a generator expression instead.

Any

No

no-string-type-annotation

Remove the quotes from this annotation; postponed evaluation is already enabled.

Any

Yes

replace-union-with-optional

Optional[T] is preferred over Union[T, None] or Union[None, T].

Any

No

use-assert-equal

Use assertEqual() or assertNotEqual() instead of wrapping an equality comparison in assertTrue().

Any

Yes

use-assert-in

Use assertIn() or assertNotIn() for membership checks.

Any

Yes

use-assert-is-not-none

Use assertIsNone() or assertIsNotNone() for None checks.

Any

Yes

use-async-sleep-in-async-def

Do not call blocking time.sleep inside async functions; use asyncio.sleep or an async runtime sleep.

Any

No

use-cls-in-classmethod

When using @classmethod, the first argument must be cls.

Any

Yes

use-collections-abc

Import abstract base classes from collections.abc.

>= 3.3

Yes

use-comprehension

Replace this {func}() call with the equivalent comprehension.

Any

No

use-eq-for-primitives

Use == or != for numeric and string values; is tests object identity.

Any

Yes

use-f-string

Use an f-string instead of % formatting or str.format().

Any

Yes

use-is-for-singletons

Compare None, True, and False with is or is not.

Any

Yes

use-literal

Replace this {func}() call with the equivalent collection literal.

Any

Yes