Skip to content

Tighten linting: every ruff rule, basedpyright in all mode failing on warnings, strict pytest - #16

Merged
nbarrett-anet merged 23 commits into
mainfrom
lint-ratchet
Nov 25, 2026
Merged

nbarrett-anet merged 23 commits into
mainfrom
lint-ratchet

Conversation

@nbarrett-anet

@nbarrett-anet nbarrett-anet commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Linting, type checking and the test run are tightened, and each now fails on anything it reports.

  • basedpyright runs in all mode over pyvelo and the examples, and any warning fails the check (failOnWarnings = true). On main, the extra rules of the recommended mode only warned, so CI passed with them reported. An example is the unannotated self._hubs in hub_steps.py.
  • ruff selects ALL. Each rule that is off is listed in pyproject.toml with its reason.
  • pytest runs with --strict-markers, --strict-config, xfail_strict and filterwarnings = ["error"].
  • pytest runs in parallel with pytest-xdist: one worker per vCPU (-n logical), with --dist worksteal and --durations=15. The suite takes 12 s instead of 50 s on 12 vCPUs.

Each tool works as a ratchet. A rule the code doesn't yet meet goes in an "Off until the code meets them" list. To turn one on, delete its line and fix what it reports. The ruff list is now empty. The basedpyright list still has the rules named under follow-ups.

What is off for good

Rule Why
ruff COM812, ISC001 conflict with the formatter
ruff CPY001 the licence is in LICENSE
ruff ANN401, basedpyright reportAny, reportExplicitAny VCO payloads are JSON, so Any is how the wire types are written
ruff SLF001 basedpyright's reportPrivateUsage checks it, with its own ignores
ruff TRY003, EM101, EM102 an exception's message is written where it is raised
ruff RUF036 the convention is X | None | MISSING, with the unset sentinel last
basedpyright reportImplicitStringConcatenation long messages are split across lines this way

Tests also skip asserts (S101), docstrings (D1) and magic values (PLR2004), plus a few security rules that don't apply to test data; each has a comment. The wire classes under client/schemas, client/models and client/enums need a module docstring, but no class or method docstrings.

What changed in the code

  • Docstrings are required outside the wire classes, in Google style.
  • Lines are at most 88 columns, and the whole tree is rewrapped. Each rewrap passed an AST comparison that ignores only docstring whitespace, showing that no code changed.
    • About 900 docstring summaries were too long for one line. Because D205 wants a one-line summary followed by a blank line, each was reworded into a short summary plus a body that holds the rest. No facts were dropped, though some of the new bodies are thin.
    • 80 test names are over 88 characters on their own and carry # noqa: E501 (a test's name).
    • Shell commands in the Usage: docstrings are split with \ continuations, and those six docstrings are now raw strings.
  • Complexity rules (C901 and the PLR09xx limits) are on. The 128 existing functions over a limit carry a noqa marked (existing: split it when it next changes). 88 of them are over the limit on arguments (PLR0913).
  • Type-checking imports. TC keeps a model's field imports at runtime through runtime-evaluated-base-classes. The new tests/test_models_build.py rebuilds every pydantic model, with each generic model built for each of its type parameters (1021 cases). An import moved under TYPE_CHECKING that a model needs therefore fails a test.
  • basedpyright fixes.
    • reportUnreachable showed that _hub_steps and conditional_backhaul in config/state.py compared a Literal with a StrEnum. basedpyright then treated most of both functions as unreachable. They now compare with .value.
    • Unneeded # pyright: ignores are removed. The 46 that name a reportUnknown* rule are kept for when those rules go on.

Parallel tests

  • -n logical and not auto. With psutil installed, auto counts physical cores, which is 6 here, and the suite then takes 18 s. Without psutil, both give the vCPU count. CI's runners have 4 vCPUs.
  • worksteal and not the default load. The default splits the tests among workers up front, and the workers that finish early then sit idle. With load the suite took 22 s.
  • The live tests run in one process. A pytest_xdist_auto_num_workers hook in tests/conftest.py evaluates -m. If it selects a read-only or a writing live test, the hook returns no workers. Otherwise each worker would connect its own client, each with its own rate limit, so together they could exceed the VCO's limit many times over, and the live_write tests would write to the one enterprise at once. An explicit -n 3 still gets its 3 workers. The hook imports pytest's Expression from _pytest.mark.expression, so it may need a change on a pytest upgrade.
  • Running one file with the default workers takes 4.9 s instead of 1.8 s. Pass -n0 for that. --pdb goes back to one process by itself. The README says this.
  • Memory: about 5 GB in total across the 12 workers.

Public API changes

There are no users yet, so these changes come without shims:

  • Boolean parameters are keyword-only: redo_patch(*, include_clashes), not_redone, confirm_save(message, *, auto_yes, plan), repaired_entry(..., *, conditional_backhaul) and hub_in_use_message(..., *, refuse).
  • Renames that stop shadowing builtins:
    • type → type_ in the firewall metrics methods.
    • GroupByProxy.agg's sum/min/max → sum_/min_/max_.
    • make_jsonrpc_response's id → id_.
    • The portal methods' ResultType/ItemType → result_type/item_type.
  • Private names that other modules used are now public:
    • PaginatedVcoModel gains max_pages (a property with a setter), page_has_more, page_next_link and record_page_cursor().
    • MetricFrame._from_polars is now from_polars.
  • Errors:
    • The 37 library asserts become explicit raises: TypeError for a wrong module type, ValueError for a bad argument, and AssertionError for an internal invariant.
    • run_diagnostic(max_retries=-1) now raises ValueError.
  • zip(..., strict=True) everywhere. In core/merge.py's _check_fixed_value, unequal lengths now raise where they were silently truncated before.

Worth a look

  • core/merge.py _check_fixed_value: confirm that the lengths are always meant to be equal there.
  • core/show.py: RUF071 wanted os.path.commonprefix replaced by commonpath. The code wants a character prefix, so it keeps commonprefix with a noqa.
  • The reworded docstring summaries, if you'd rather keep the original wording. The alternative is to turn D205 off for good and restore the original long summaries, wrapped.

Testing

  • scripts/check.sh passes:
    • ruff check and ruff format --check are clean.
    • basedpyright reports 0 errors and 0 warnings.
    • pytest: 7860 passed, 2 skipped, 151 deselected. main had 6839 passed; the difference is the 1021 new model-build cases. The parallel suite passed on four runs in a row.
    • With each -m selection, the worker count is as described above: 12 for the default, and one process for integration, integration and not live_write, live_write and an empty -m.
  • The live tests weren't run against a VCO.

Follow-ups

  • Turn on basedpyright's reportUnknownVariableType, reportUnknownArgumentType, reportUnknownMemberType and reportUnknownLambdaType (about 540 warnings), and reportUnusedCallResult (153).
  • After that, turn on reportUnnecessaryTypeIgnoreComment. While a reportUnknown* rule is off, every ignore that names it counts as unnecessary.

Turns on reportUnnecessaryIsInstance, reportUnnecessaryComparison,
reportUnnecessaryContains, reportUnreachable, reportUnnecessaryCast,
reportUnusedFunction and reportDeprecated.

Module-name lookups in ConfigState compare against the enum's value, so
the checker no longer narrows the module to None and calls the hub-step
and conditional-backhaul code unreachable. Dead checks and casts are
removed; guards against caller input outside the declared types are
kept with a targeted ignore.
Annotate each instance and class attribute the rule reports: pydantic
model_config as ClassVar[ConfigDict] (the convention core/base.py already
follows), __slots__ as ClassVar[tuple[str, ...]], resolver identity_type
with the resolver's own identity type, and instance attributes where
__init__ assigns them. Two test lines that exist to provoke a checker
error or build a pydantic validator keep their form and ignore the rule.
Imports used only in annotations move under TYPE_CHECKING, except where
pydantic reads them: the model base classes are listed in
runtime-evaluated-base-classes. Local imports move to the top, except
those that break an import cycle or load an optional extra, which keep a
noqa with the reason.
…15 slowest

pytest-xdist with -n logical and --dist worksteal: the suite takes 12 s in
place of 50 s on 12 vCPUs. A selection that takes in a live test runs in one
process, since each worker would connect its own client with its own rate
limit, and the tests that write would write to the one enterprise at once.
@nbarrett-anet
nbarrett-anet merged commit 9cd680c into main Nov 25, 2026
3 checks passed
@nbarrett-anet
nbarrett-anet deleted the lint-ratchet branch November 25, 2026 16:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant