Skip to content

unsorted-dunder-slots (RUF023)#

Fix is sometimes available.

This rule is unstable and in preview. The --preview flag is required for use.

What it does#

Checks for __slots__ definitions that are not ordered according to a natural sort.

Why is this bad?#

Consistency is good. Use a common convention for this special variable to make your code more readable and idiomatic.


class Dog:
    __slots__ = "name", "breed"

Use instead:

class Dog:
    __slots__ = "breed", "name"