Skip to content

Ordering Rules

The ordering rules reorder sibling AST nodes by a deterministic key while preserving attached comments and inter-section gaps. The shared machinery lives in the Orderer primitive, with each rule supplying the classifier closure that names the sort key. A pinning shape lets specific items (class docstrings, module-level imports above a divider comment) stay in their authored slot while the rest of the siblings redistribute.

alphabetize

Ordering

Alphabetizes import siblings, dict-key blocks, and class-body members.

band-constants

Ordering

Hoists module-level constants into a leading band below the imports and a trailing band beneath the definitions.

group-imports

Ordering

Partitions a module's imports into bare, external from, and local-package sections.

For the comment-attachment semantics and the gap_override machinery, see the Orderer primitive page. The # prose: keep directive (documented in Suppression Directives) opts a dict literal out of

when the entry order carries meaning the rule can't infer, and the rule's sort-dict-keys facet declines the reorder across a whole project.