Skip to content

v0.2.0

Choose a tag to compare

@github-actions github-actions released this 14 Jun 18:05
Immutable release. Only release title and notes can be modified.

Added

  • Sort module- and class-level assignments. Within every scope the order is now
    assignments, then classes, then functions/methods, so methods always follow nested
    classes and assignments are grouped at the top. Assignments are split into uppercase
    CONSTANTS first and then other variables; each group sorts with a leading
    underscore first (so __dunder__ and _private precede public names), and
    dependencies are respected (B = A + 1 stays after A). As a result,
    module-level functions now sort after module-level classes. The attribute order of
    enums, dataclasses, and NamedTuple/TypedDict classes is preserved; the base or
    decorator is resolved through QualifiedNameProvider so aliased imports (from enum import IntEnum as IE) are recognized.
  • Keep blank-line spacing with its position rather than the moved definition, so
    reordering no longer drags a blank line onto a different statement (for example the
    blank line after a class docstring stays at the top of the block). Comment lines that
    sit directly above a definition still travel with it.
  • Keep an augmented assignment anchored to the constant it augments, so __all__ += extra stays directly after __all__ = [...] instead of being left behind as a
    fixed barrier when another assignment sorts between them.
  • Sort keyword arguments in calls, keyword-only parameters in function definitions, and
    string keys in dict literals alphabetically. In a call, keyword arguments are sorted
    and ** unpackings moved to the end (positional arguments and * unpackings stay
    put), which is safe because a call raises TypeError on any duplicate keyword
    regardless of order. In a dict literal, ** spreads and non-string keys act as
    barriers so last-wins merge semantics are preserved.

Changed

  • Sort _-prefixed (private and dunder) names ahead of public names at every level
    rather than after capitalized names. A plain string sort placed _ after
    A-Z because of its higher code point; names are now ordered on a
    leading-underscore flag first so private definitions, methods, keyword arguments, and
    dict keys group together ahead of the public ones.

Fixed

  • Ignore a name used only in a lazy annotation (under from __future__ import annotations) when ordering definitions, since the annotation is never evaluated at
    runtime and imposes no real dependency. A forward reference in an annotation (for
    example nxt: list[Instr] where Instr is a type-alias union of classes defined
    later) previously forged a false dependency cycle that could hoist the runtime alias
    above the classes it unions and raise NameError.
  • Order definitions with a proper priority topological sort so a class or function is
    always placed after every sibling it depends on. The previous dependency heuristic
    compared per-node dependency vectors and could emit a dependent before its dependency
    (for example, Subreddit's SubredditFlair was sorted ahead of the
    flair-template classes it instantiates).