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

Missing blank line after multiline control-flow block statement.

Any

Yes

blank-line-before-assignment

Missing blank line before assignment statement that follows a non-assignment statement.

Any

Yes

blank-line-before-branch

Missing blank line before return/raise/break/continue in a large suite.

Any

Yes

blank-line-before-unrelated-block

Illegal cuddle before block header. The preceding setup must directly feed the upcoming block.

Any

Yes

no-suite-leading-trailing-blank-lines

Any

Yes

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

Instead of NamedTuple, consider using the @dataclass decorator from dataclasses instead for simplicity, efficiency and consistency.

Any

Yes

no-static-if-condition

Your if condition appears to evaluate to a static value (e.g. or True, and False). Please double check this logic and if it is actually temporary debug code.

Any

No

sorted-attributes

It appears you are using the @sorted-attributes directive and the class variables are unsorted. See the lint autofix suggestion.

Any

Yes

use-callable-ellipsis

Any

Yes

use-rattle-ignore-comment

noqa is deprecated. Use rattle: ignore[rule-name] instead.

Any

No

use-types-from-typing

< 3.10

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

Yes

deprecated-unittest-asserts

{deprecated} is deprecated, use {replacement} instead

Any

Yes

no-inherit-from-object

Inheriting from object is a no-op. ‘class Foo:’ is just fine =)

Any

Yes

no-or-in-except

Avoid using ‘or’ in an except block. For example:’except ValueError or TypeError’ only catches ‘ValueError’. Instead, use parentheses, ‘except (ValueError, TypeError)’

Any

No

no-redundant-arguments-super

Do not use arguments when calling super for the parent class.

Any

Yes

no-redundant-f-string

f-string doesn’t have placeholders, remove redundant f-string.

Any

Yes

no-redundant-lambda

Any

Yes

no-redundant-list-comprehension

Any

Yes

no-string-type-annotation

String type hints are no longer necessary in Python, use the type identifier directly.

Any

Yes

replace-union-with-optional

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

Any

Yes

use-assert-equal

“assertTrue” does not compare its arguments, use “assertEqual” or other appropriate functions.

Any

Yes

use-assert-in

Use assertIn/assertNotIn instead of assertTrue/assertFalse for inclusion check.

Any

Yes

use-assert-is-not-none

“assertTrue” and “assertFalse” are deprecated. Use “assertIsNotNone” and “assertIsNone” instead.

Any

Yes

use-async-sleep-in-async-def

Use asyncio.sleep in async function

Any

No

use-cls-in-classmethod

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

Any

Yes

use-collections-abc

ABCs must be imported from collections.abc

>= 3.3

Yes

use-comprehension

Any

Yes

use-eq-for-primitives

Don’t use is or is not to compare primitives, as they compare references. Use == or != instead.

Any

Yes

use-f-string

Do not use printf style formatting or .format(). Use f-string instead to be more readable and efficient.

Any

Yes

use-is-for-singletons

Comparisons to singleton primitives should not be done with == or !=, as they check equality rather than identity. Use is or is not instead.

Any

Yes

use-literal

Any

Yes