Skip to content

Enable ruff docstring rules (D) - #3907

Draft
anth-volk wants to merge 12 commits into
ruff-annotationsfrom
ruff-docstrings
Draft

anth-volk wants to merge 12 commits into
ruff-annotationsfrom
ruff-docstrings

Conversation

@anth-volk

Copy link
Copy Markdown
Collaborator

Fixes #3906

Summary

Phase 1 step 1.8, group 4: docstrings. Stacked on #3905.

  • Docstrings: select gains D and ignores D203 and D213, keeping D211 (no blank line before a class docstring) and D212 (summary on the first line). All 1,336 findings at the base are fixed: about 1,000 docstrings added or reworded across 229 Python files, committed by area (runtime cache and libraries, rules tool and scripts, data layer, v2 services, FastAPI routes and models, Flask routes and utilities, v1 services). Existing docstrings were reworded to say what the code actually does; one test docstring said 404 where the code returns 400.
  • Code is unchanged apart from docstrings. An AST comparison with the base, ignoring docstrings, pass and ..., finds one other change, which is equivalent. In full:
    • 27 classes whose body was only pass now have a docstring instead, because PIE790 flags pass after a docstring.
    • Protocol stubs keep ... after their new docstring.
    • The disabled cache backend's get() drops its redundant return None instead of suppressing RET501.
  • Suppressions: no noqa: D… anywhere. The two validator proof fixtures for api.v2.validators-transformations-no-db get one-line docstrings rather than a per-file ignore.
  • Published schema text changes (agreed): Pydantic copies a class docstring into the model's JSON-schema description, and FastAPI copies a route docstring into the operation description. Compared with the base, with description keys removed:
    • Structure is identical: the same paths, operations, properties, types and required lists in all 234 model schemas, the FastAPI OpenAPI (every native router enabled) and the /v2/openapi.json preview.
    • Published OpenAPI: 57 component descriptions added, written for API consumers. No field or operation descriptions changed.
    • Model schemas: 128 models gained or changed their own description (127 new; EconomicImpactResult reworded).
    • Legacy spec: byte-identical. No checked-in schema snapshot needed regenerating.
  • Shared rules tool: scripts/rules is byte-identical with sim again (tool sha256 db83d5ad2aa4); sim adopts this PR's wording in Enable ruff docstring rules (D) policyengine-sim-api#779.
  • Registry: api.quality.ruff-lint now lists D.

Testing

  • pytest tests/unit tests/contract, to_refactor and the dedupe integration test (the make test set): 2,411 passed.
  • mypy (configured scope) is clean. ruff check and ruff format --check (0.15.12) are clean repo-wide.
  • Quality guards, the rules guard and the rules tool unittest pass.

🤖 Generated with Claude Code

@anth-volk
anth-volk added this pull request to stack #3888 October 13, 2026 13:29
@codecov

codecov Bot commented Oct 13, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 24.32432% with 56 lines in your changes missing coverage. Please review.
✅ Project coverage is 43.77%. Comparing base (ca36072) to head (376029d).

Files with missing lines Patch % Lines
policyengine_api/fastapi_routes/dependencies.py 9.75% 37 Missing ⚠️
policyengine_api/runtime_cache/core.py 50.00% 14 Missing ⚠️
policyengine_api/api.py 0.00% 1 Missing ⚠️
policyengine_api/services/household_mirroring.py 0.00% 1 Missing ⚠️
policyengine_api/services/policy_mirroring.py 0.00% 1 Missing ⚠️
policyengine_api/services/user_policy_mirroring.py 0.00% 1 Missing ⚠️
policyengine_api/worker_spm.py 0.00% 1 Missing ⚠️

❗ There is a different number of reports uploaded between BASE (ca36072) and HEAD (376029d). Click for more details.

HEAD has 1 upload less than BASE
Flag BASE (ca36072) HEAD (376029d)
2 1
Additional details and impacted files
@@                  Coverage Diff                  @@
##           ruff-annotations    #3907       +/-   ##
=====================================================
- Coverage             85.38%   43.77%   -41.61%     
=====================================================
  Files                   198      183       -15     
  Lines                 12400    11284     -1116     
  Branches               2264     1954      -310     
=====================================================
- Hits                  10588     4940     -5648     
- Misses                 1111     5893     +4782     
+ Partials                701      451      -250     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@anth-volk
anth-volk removed this pull request from stack #3888 October 13, 2026 19:26
@anth-volk
anth-volk added this pull request to stack #3917 October 13, 2026 19:26
@anth-volk
anth-volk force-pushed the ruff-docstrings branch 3 times, most recently from f9c71e0 to c14b631 Compare October 14, 2026 18:08
@anth-volk
anth-volk force-pushed the ruff-docstrings branch 8 times, most recently from 31126f6 to bfed2d6 Compare October 15, 2026 00:06
@anth-volk
anth-volk force-pushed the ruff-docstrings branch 2 times, most recently from 36d64ce to 3d9fa59 Compare October 15, 2026 15:45
anth-volk and others added 5 commits October 15, 2026 21:12
Run ruff check --fix for the pydocstyle (D) rules: put summaries on the
first line, drop blank lines after function docstrings, and normalise
blank lines around sections and closing quotes. Only docstring
whitespace changes; the published OpenAPI documents and Pydantic JSON
schemas are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Tests are exempt from the missing-docstring rules (D1) but not from the
style rules, so give each flagged test and fixture docstring a one-line
imperative summary followed by a blank line, describe the parameters
the numpy-style sections left out, and correct the validate_country
test class, which said 404 where the decorator returns 400.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add docstrings to the Redis-backed runtime cache (its Protocols, the
in-memory fake, claims and the household and reform-impact caches), the
observability runtime and stage plans, and the gateway client and auth
helpers. Each says what a reader cannot see from the signature: what a
miss means, when entries are rejected, and which Redis behaviour a fake
command emulates.

Adding a docstring to the fake backend's get makes RET501 report its
explicit return None, which stays and is suppressed with a reason.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add docstrings to scripts/rules (the registry model, loader, resolver,
validator and renderer), the quality-guard runner and migration guard,
the migration baseline, mirroring and smoke-test scripts, the Alembic
environments, and the .github helper scripts. Reword the rules tool's
noun-phrase function summaries into the imperative and give its
multi-line summaries a separating blank line.

scripts/rules is the canonical copy of a tool shared byte-for-byte with
policyengine-sim-api, and the argparse help taken from module
docstrings is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add docstrings to the v1 SQLAlchemy models and connection settings, the
congressional-district metadata, the v2 catalog publication records and
staging, the household and policy migration qualification, the v2
migration target settings, and the v2 SQLModel tables and their enums.

The table docstrings say what a row represents: what makes it unique,
whether it is immutable, what owns it and what is deleted with it.
Pydantic publishes a class docstring as the model's JSON-schema
description, so these tables' schemas gain descriptions; none of them is
in the published OpenAPI document.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
anth-volk and others added 7 commits October 15, 2026 21:12
Add docstrings to the v2 resource services (households, policies,
user-households and user-policies), the metadata catalog service, and
the comparison-run, simulation and report contracts: their sessions,
database connectors, transformations, validators and types. They say
what each read returns when nothing matches, which writes are
deduplicated or idempotent, which typed errors are raised, and how the
limit + 1 over-fetch drives has_more.

Pydantic publishes class docstrings as JSON-schema descriptions. The
metadata result types appear in the published OpenAPI document, so
their docstrings are written for API consumers; the simulation and
report types are the versioned Stage 12 worker contracts, so theirs
describe what each message means to producer and consumer.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add docstrings to the native route dependencies (one contract line per
Protocol method), the health, metadata and specification routers, the
v2 metadata route builders and their shared read_resource helper, and
the v2 request, document and response models and their methods.

Pydantic publishes a model's class docstring as its JSON-schema
description, so the response and document models in the OpenAPI
document now carry descriptions written for API consumers: what each
object represents, that households and policies are immutable and
deduplicated, and how to page through results. Route functions, whose
docstrings FastAPI would publish as operation descriptions, are
unchanged, and so are the documented paths and operations.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add module, function and class docstrings to the Flask blueprints, the
payload validators and utilities, and the top-level application,
constants, country, SPM, migration-flag and query-parameter modules.
Reword the existing error-handler, user-profile, policy and cache-key
docstrings into one-line imperative summaries, complete the Args
sections of get_policy, set_policy and validate_country (whose entry
described the wrapper's argument instead of the decorator's), and drop
the update_user_profile promise of a 403 for auth0_id edits, which the
code never makes.

Only validator methods on the published SPM and query-parameter models
gained docstrings; their class docstrings are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add docstrings to the v1 economy, household, policy, report, simulation
and user services, their legacy-to-v2 mirroring helpers and the budget-
window cache, including their Pydantic option, result and spec models.
They say what a reader cannot see from the signature: which results are
cached and how, which writes are mirrored to v2, what None means, and
which errors are raised. Reword the existing summaries that ran on
without a blank line or past 88 columns, correct get_economic_impact,
which claimed to return a tuple, and replace the pass bodies of two
exception classes with their new docstrings.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Select the pydocstyle rules (D), keeping D211 and D212 of the two
mutually exclusive pairs. Test files stay exempt from the
missing-docstring rules (D1) but follow the docstring style rules.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The two validator fixtures were the last D103 findings. The disabled
cache backend's get() now ends at its docstring instead of suppressing
RET501 on an explicit return None.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
api.quality.ruff-lint now lists D, and the rendered rules page and
AGENTS.md Rules block are regenerated for the new tool hash.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch was successfully deployed

1 active (outdated) deployment
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.

Enable ruff docstring rules (D)

1 participant