• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

HEROgold / funcsort / 30719014411

01 Aug 2026 09:22PM UTC coverage: 96.497% (+3.8%) from 92.732%
30719014411

push

github

web-flow
fix: never reorder a definition below code that reads it at import time (#2)

* fix: never reorder a definition below code that reads it at import time

funcsort ordered class and module bodies purely by group, with no model of
load-time name dependencies. Anything a statement reads *while it executes* --
a decorator expression, a parameter default, an assignment RHS -- must already
be bound, so sorting could hoist a definition above its referent and leave the
file raising NameError on import.

It hit this repo: `@given(_class_source())` on a public `test_*` function was
sorted above the protected `_class_source` it calls.

Two new modules, mirroring the existing pure/adapter split:

- references.py (libcst adapter) separates eager references, which constrain
  ordering, from lazy ones, which never do. Function and lambda bodies are lazy,
  so mutual recursion still sorts freely; class bodies are eager; annotations
  are eager unless the module uses `from __future__ import annotations`.
  Over-collection is the safe direction and is preferred throughout.

- ordering.py (pure) fits the preferred order to those constraints. Anchors hold
  fixed indices and candidates fill the remaining slots, subject to precedence
  edges, release times and deadlines. A valid desired order is emitted verbatim,
  so dependency-free code is byte-identical to before; otherwise a deterministic
  earliest-deadline-first greedy repairs it. Since the input file already runs,
  its own order is always feasible and is the fallback when no safe order is
  found -- funcsort warns rather than emitting code that cannot import.

sort_block now iterates bucketing and solving to a fixed point. The
minimise-movement heuristic is position-dependent, so without this a repaired
order could oscillate and rewrite the same file on alternate pre-commit runs.

Exposed as `respect_dependencies` (default true) plus --no-respect-dependencies,
wired like the existing sort_module flag.

Only members... (continued)

720 of 728 new or added lines in 13 files covered. (98.9%)

26 existing lines in 5 files now uncovered.

1873 of 1941 relevant lines covered (96.5%)

0.96 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.83
/src/funcsort/groups.py


Build SHA Not Found

The commit SHA "759aac15ac091b053e98b287bdee9167ce46d4bb" was not found in your repository, so the file cannot be loaded. This may be because you posted from a local development environment, or your CI created an ephemeral commit.

STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc