alphabetize
OrderingProse alphabetizes import siblings, dict-key blocks, and
Blank lines carry rhythm. They tell the reader where one unit ends and the next begins, and a consistent rhythm across a file lets the reader skim by section without parsing each statement.
normalizes the discipline around module-level definitions, class members, and theif __name__ == "__main__": guard, so every file in the project reads with the same cadence.Module-level def and class carry two blank lines before them and two after when followed by a top-level assignment. Methods inside a class body carry one, a module-level statement after if __name__ == "__main__": carries one, and adjacent bare-import and from-import groups carry one between them. Inside function bodies the rule leaves blank-line discipline alone, since the in-body rhythm remains a per-author choice. A description-shaped own-line comment block above a statement binds tight against the following statement, reading the comment as a description of the statement it precedes, whereas a banner-shaped block (with any line a decorative rule of =, -, *, _, #, or ~) keeps 1 blank line below to read as a section divider. The canonical above-gap is measured from the topmost comment in the block either way. The import surface sits downstream of
import keyword.| Key | Type | Default | Meaning |
|---|---|---|---|
enabled | bool | true | Toggle the rule on or off |
The canonical blank-line counts are hard-coded to PEP 8's 2-between-top-level and 1-between-methods cadence, so the rule carries enabled as its only knob. Projects that want a different cadence can disable the rule and let their editor's blank-line conventions stand.
Two def and class, giving the reader's eye an anchor between top-level units.
for setup in initial_steps:
setup.run()
def main():
return 0
A
A banner-style block of def reads as a section divider, not a description of the def. The canonical gap lands above the banner, with one
A comment between two statements reads as the second statement's leading block. The canonical gap normalizes above the comment and the comment binds tight against the following statement, collapsing any blank-count drift in the source.
A def with a leading
A bare import followed by a from import with two
Two methods inside a class body normalize to one
A bare import butted directly against a from import with zero
A if __name__ == "__main__": block carries one
A class carrying its own (docstring, method) pair, collapsing any wider drift below.
A bare import and a following from import already separated by one